Documentation Index
Fetch the complete documentation index at: https://mintlify.com/tanstack/router/llms.txt
Use this file to discover all available pages before exploring further.
Hooks API
Type-safe hooks for accessing router state and navigation.useRouter
Access the current TanStack Router instance from React context.
Options
Log a warning if no router context is found.
Returns
The registered router instance with methods like
navigate, invalidate, preloadRoute, etc.useNavigate
Imperative navigation hook.
Options
Optional route base used to resolve relative
to paths.Returns
A stable function that accepts
NavigateOptions:to- Destination route pathparams- Path parameterssearch- Search parameters (object or updater function)hash- Hash fragmentstate- History statereplace- Replace history entry instead of pushresetScroll- Reset scroll positionviewTransition- Use View Transitions API
useParams
Access the current route’s path parameters with type-safety.
Options
The route path to get params from. Enables strict typing.
If
true, only the route’s own params are returned. If false, all params from parent routes are included.Project the params object to a derived value for memoized renders.
Enable structural sharing for stable references.
Returns
The params object (or selected value) for the matched route.
useSearch
Read and select the current route’s search parameters with type-safety.
Options
The route path to get search params from. Enables strict typing.
Control which route’s search is read and how strictly it’s typed.
Map the search object to a derived value for render optimization.
Enable structural sharing for stable references.
Returns
The search object (or selected value) for the matched route.
useLoaderData
Read and select the current route’s loader data with type-safety.
Options
The route path to get loader data from. Enables strict typing.
Choose which route’s data to read and strictness.
Map the loader data to a derived value.
Enable structural sharing for stable references.
Returns
The loader data (or selected value) for the matched route.
useLoaderDeps
Access the current route’s loader dependencies.
Options
The route path to get loader deps from.
Control strictness of typing.
Map the deps to a derived value.
Returns
The loader dependencies for the matched route.
useMatch
Get the current route match data.
Options
The route path to match against.
Whether to enforce strict typing.
Select a derived value from the match.
Enable structural sharing for stable references.
Returns
The route match object containing:
id- Unique match identifierrouteId- The route’s IDpathname- The matched pathnameparams- Path parameterssearch- Search parametersloaderData- Data from the loaderstatus- Match status (‘pending’ | ‘success’ | ‘error’)- And more…
useLocation
Get the current location object.
Returns
The current location object with:
href- The full URL pathpathname- The pathnamesearch- Parsed search parameterssearchStr- Raw search stringhash- The hash fragmentstate- History state
useRouterState
Subscribe to router state with optional selection.
Options
Select a derived value from the router state.
Enable structural sharing for stable references.
Returns
The router state (or selected value) containing:
status- Router status (‘pending’ | ‘idle’)isLoading- Whether the router is loadingisTransitioning- Whether a navigation is in progressmatches- Current route matcheslocation- Current locationresolvedLocation- Resolved location after redirects
useRouteContext
Access the current route’s context.
Options
The route path to get context from.
Whether to enforce strict typing.
Select a derived value from the context.
Returns
The route context object.
useBlocker
Block navigation based on a condition.
Options
Whether to block navigation.
A function that returns
true to allow navigation or false to block it.Returns
Void. The hook sets up the blocker internally.useMatches
Get all current route matches.
Options
Select a derived value from the matches array.
Enable structural sharing for stable references.
Returns
Array of all current route matches from root to leaf.
useCanGoBack
Check if the router can go back in history.
Returns
Whether the router can navigate back in history.