-
-
Notifications
You must be signed in to change notification settings - Fork 0
useRouteNodeStore
olegivanov edited this page May 18, 2026
·
1 revision
Solid.js only. For React/Preact/Vue/Svelte/Angular use
useRouteNode.
-
Name:
useRouteNodeStore -
Purpose: Subscribe to a specific route node with granular, property-level reactivity via Solid's
createStore+reconcile -
When to use: When a component should update only when a named route node (and its descendants) is active or inactive, AND needs property-level tracking within that state — combining the node-scope optimization of
useRouteNodewith the granular reactivity ofuseRouteStore
function useRouteNodeStore(nodeName: string): RouteStateimport { useRouteNodeStore } from "@real-router/solid";| Parameter | Type | Required | Description |
|---|---|---|---|
nodeName |
string |
Yes | Route node name to scope the subscription to. "" subscribes to all changes (same as useRouteStore). |
Returns a Solid store (RouteState) scoped to the named node. The store updates only when the named node transitions between active and inactive, or when its route/previousRoute changes:
interface RouteState {
route: State | undefined; // defined only when nodeName is active
previousRoute: State | undefined;
navigator: Navigator;
}useRoute() |
useRouteNode(name) |
useRouteStore() |
useRouteNodeStore(name) |
|
|---|---|---|---|---|
| Returns | Accessor<RouteState> |
Accessor<RouteState> |
RouteState (store) |
RouteState (store) |
| Read syntax | state() |
state() |
state.route |
state.route |
| Updates on | every navigation | node active/inactive | every navigation | node active/inactive |
| Property-level tracking | ✗ | ✗ | ✅ | ✅ |
import { useRouteNodeStore } from "@real-router/solid";
import { Show } from "solid-js";
function UsersLayout() {
// Updates only when "users" or "users.*" routes activate/deactivate
const state = useRouteNodeStore("users");
return (
<Show when={state.route}>
{(route) => (
<div>
{/* Each field tracked independently */}
<h1>Users — {route().params.section ?? "list"}</h1>
<p>Previous: {state.previousRoute?.name}</p>
</div>
)}
</Show>
);
}function UserBreadcrumb() {
const state = useRouteNodeStore("users");
// Re-runs only when params.id changes, not on unrelated navigations
return <span>{state.route?.params.id ?? "—"}</span>;
}// nodeName="" → same update frequency as useRouteStore()
const state = useRouteNodeStore("");useRouteNodeStore wraps createRouteNodeSource(router, nodeName) in createStoreFromSource:
-
createRouteNodeSourceis a cached source per(router, nodeName)pair — N components sharing the same node name share one router subscription - The source emits only when
nodeName's active state changes — navigations that don't affectnodeNameare silently dropped by the source'sshouldUpdateguard - On each emit,
createStoreFromSourcecallssetState(reconcile(source.getSnapshot()))— reconcile updates only changed paths, preserving unchanged object identity for Solid's fine-grained tracking - Calls
onCleanup(unsubscribe)— the subscription releases when the reactive owner is disposed; if the source has no remaining listeners, it disconnects from the router automatically
- Must be called inside a reactive owner (component body or
createRoot) -
state.routeisundefinedwhennodeNameis not active — a legitimate business state, not a lifecycle error (contrast:useRoute()throws if no active route) - Source cache lives in
@real-router/sources— auto-evicted on router GC, no local teardown needed -
previousRoutereflects the global previous route, not the node's previous state — seeuseRouteNodegotcha #8 in CLAUDE.md
-
useRouteStore— same granular store pattern, not node-scoped -
useRouteNode— accessor-based node subscription (re-renders on any node change) - Solid Integration Guide — Store-Based Hooks
- View-Agnostic Design
- Core Concepts
- Navigation Lifecycle
- Guards
- Plugin Architecture
- Hash Fragment Support
- Accessibility (A11y)
- Server-Side Rendering
- Data Loading
- Streaming SSR
- SSR Cancellation
- RSC Integration
- Testing
- Glossary
Tree-shakeable functions — import only what you need.
- add (addRoute)
- remove (removeRoute)
- replace (replaceRoutes)
- clear (clearRoutes)
- get (getRoute)
- has (hasRoute)
- update (updateRoute)
- get (getDependency)
- getAll (getDependencies)
- set (setDependency)
- setAll (setDependencies)
- has (hasDependency)
- remove (removeDependency)
- reset (resetDependencies)
For plugin authors, not for general use.
- makeState
- buildState
- buildNavigationState
- forwardState
- getForwardState
- setForwardState
- matchPath
- setRootPath
- getRootPath
- navigateToState
- addEventListener
- getRouteConfig
- getOptions
- addBuildPathInterceptor
- extendRouter
- getTree
- React Integration Guide
- Preact Integration Guide
- Solid Integration Guide
- Vue Integration Guide
- Svelte Integration Guide
- Ink (Terminal UI) Integration Guide
- Desktop (Electron, Tauri) Integration Guide
- useRouter
- useRoute
- useRouteNode
- useNavigator
- useRouteUtils
- useRouterTransition
- useRouteExit
- useRouteEnter
- useRouteStore (Solid only)
- useRouteNodeStore (Solid only)
SSR-feature subpath —
@real-router/{adapter}/ssr. Symmetric across React/Preact/Solid/Vue/Svelte.
- Lazy (Svelte only — dynamic component import)
- Await — read deferred SSR data by key
- Streamed — Suspense-style boundary
- ClientOnly — server fallback → client children swap
- ServerOnly — server children, removed after hydration
- HttpStatusCode — render-time HTTP status declaration
-
HttpStatusProvider — provides sink to descendant
<HttpStatusCode> - useDeferred — read deferred Promise by key