Router Hooks
useRouter
Access the current TanStack Router instance from React context.
packages/react-router/src/useRouter.tsx:16-25
{ warn?: boolean }
TRouter
The registered router instance.
useRouterState
Subscribe to the router’s state store with optional selection and structural sharing.
packages/react-router/src/useRouterState.tsx:44-86
UseRouterStateOptions
TSelected | RouterState
The selected router state (or the full state by default).
Navigation Hooks
useNavigate
Imperative navigation hook that returns a stable navigate function.
packages/react-router/src/useNavigate.tsx:26-43
{ from?: string }
(options: NavigateOptions) => Promise<void>
A function that accepts NavigateOptions including:
to- Destination pathparams- Path parameterssearch- Search parametershash- URL hashreplace- Replace history entryresetScroll- Reset scroll position
useLocation
Read the current location from the router state.
packages/react-router/src/useLocation.tsx:40-52
UseLocationOptions
Location | TSelected
The current location object with properties:
pathname- Current pathsearch- Parsed search paramshash- URL hashhref- Full URLstate- Location state
Route Data Hooks
useParams
Access the current route’s path parameters with type safety.
packages/react-router/src/useParams.tsx:76-107
UseParamsOptions
required
TParams | TSelected
The params object (or selected value) for the matched route.
useSearch
Read and select the current route’s search parameters with type safety.
packages/react-router/src/useSearch.tsx:76-105
UseSearchOptions
required
TSearch | TSelected
The search object (or selected value) for the matched route.
useLoaderData
Read and select the current route’s loader data with type safety.
packages/react-router/src/useLoaderData.tsx:68-91
UseLoaderDataOptions
required
TLoaderData | TSelected
The loader data (or selected value) for the matched route.
Match Hooks
useMatch
Read and select the nearest or targeted route match.
packages/react-router/src/useMatch.tsx:82-123
UseMatchOptions
required
RouteMatch | TSelected
The route match object containing:
id- Match IDrouteId- Route IDpathname- Matched pathnameparams- Path parameterssearch- Search parametersloaderData- Loader datacontext- Route context
useMatches
Read the full array of active route matches or select a derived subset.
packages/react-router/src/Matches.tsx:233-250
UseMatchesOptions
RouteMatch[] | TSelected
The array of matches (or the selected value).
useMatchRoute
Create a matcher function for testing locations against route definitions.
packages/react-router/src/Matches.tsx:144-174
(options: MatchRouteOptions) => false | TParams
A matchRoute function that returns
false (no match) or the matched params object. Options include:to- Route to matchparams- Match specific paramssearch- Match specific searchfuzzy- Allow fuzzy matchingpending- Match against pending locationcaseSensitive- Case-sensitive matching
Blocker Hook
useBlocker
Block navigation with custom logic and optional user confirmation.
packages/react-router/src/useBlocker.tsx:131-260
UseBlockerOpts
required
void | BlockerResolver
When
withResolver: true, returns:status- ‘idle’ | ‘blocked’current- Current location infonext- Next location infoaction- History actionproceed()- Allow navigationreset()- Cancel navigation
Usage Examples
Router State Selection
Imperative Navigation
Type-Safe Params
Search Params with Selection
Loader Data Access
Conditional Rendering with Match
Breadcrumbs with Matches
Navigation Blocker
Location Tracking
Performance Tips
Use Selectors
Always use theselect option to narrow down your subscription: