-
-
Notifications
You must be signed in to change notification settings - Fork 0
useRouteStore
Solid.js only. For React/Preact/Vue/Svelte/Angular use
useRoute.
-
Name:
useRouteStore -
Purpose: Subscribe to all route changes with granular, property-level reactivity via Solid's
createStore+reconcile -
When to use: When a component reads individual fields of the route state and should not re-run when unrelated fields change — e.g., reading
state.route.namewithout reacting tostate.route.paramschanges
function useRouteStore(): RouteStateimport { useRouteStore } from "@real-router/solid";Returns a Solid store (RouteState) — a reactive proxy where each property is tracked independently:
interface RouteState {
route: State | undefined;
previousRoute: State | undefined;
navigator: Navigator;
}Access fields directly (no accessor call needed — stores are not wrapped in Accessor<T>):
const state = useRouteStore();
state.route?.name // tracked: re-runs only when `name` changes
state.route?.params.id // tracked: re-runs only when `params.id` changesuseRoute() |
useRouteStore() |
|
|---|---|---|
| Returns | Accessor<RouteState> |
RouteState (store) |
| Read syntax | state().route.name |
state.route?.name |
| Re-renders on | every navigation | only changed properties |
| Use case | simple components | performance-sensitive, fine-grained reactivity |
import { useRouteStore } from "@real-router/solid";
import { createEffect } from "solid-js";
function PageTitle() {
const state = useRouteStore();
// Re-runs only when route.name changes — not on params-only navigations
createEffect(() => {
document.title = state.route?.name ?? "App";
});
return <h1>{state.route?.name}</h1>;
}function UserProfile() {
const state = useRouteStore();
return (
<div>
{/* Each expression tracked independently */}
<h1>User: {state.route?.params.id}</h1>
<p>Previous: {state.previousRoute?.name}</p>
</div>
);
}function Layout() {
const state = useRouteStore();
return (
<Show when={state.route}>
{(route) => <p>Current: {route().name}</p>}
</Show>
);
}useRouteStore wraps createRouteSource(router) in createStoreFromSource, which:
- Initialises the store with
createStore({ ...source.getSnapshot() }) - Subscribes to source updates; on each emit calls
setState(reconcile(source.getSnapshot())) -
reconcilediffs the new snapshot against the existing store and updates only changed paths — unchanged object references are preserved, so Solid's fine-grained tracking does not notify unaffected derivations - Calls
onCleanup(unsubscribe)— the subscription is released when the reactive owner is disposed
The underlying createRouteSource is cached per router instance in @real-router/sources. Multiple components calling useRouteStore() with the same router share one source — one router subscription, one reconcile call per navigation.
- Must be called inside a reactive owner (component body or
createRoot) —createStoreFromSourcecallsonCleanup -
routemay beundefinedwhile the router is unstarted or stopped; guard withShowor optional chaining - For node-scoped granular reactivity use
useRouteNodeStore - For whole-value signal-based reactivity use
useRoute
-
useRouteNodeStore— same pattern, scoped to a specific route node -
useRoute— accessor-based, re-renders on every navigation - 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