Skip to main content

React Hooks

Type-safe React hooks for accessing router state, route data, and navigation.

useRouter

Access the router instance.

Router Methods

useRouterState

Access and subscribe to router state.

Options

(state: RouterState) => any
Select specific data from router state.

RouterState Properties

ParsedLocation
Current location object.
RouteMatch[]
Array of current route matches.
RouteMatch[]
Matches being loaded.
'pending' | 'idle'
Router status.
boolean
Whether router is loading.
boolean
Whether router is transitioning.

useLocation

Access the current location.

Options

(location: ParsedLocation) => any
Select specific data from location.

useParams

Access route parameters with type safety.

Options

string
Route ID for type inference.
boolean
Throw error if route doesn’t match.Default: true
(params) => any
Select specific params.

useSearch

Access validated search parameters.

Options

string
Route ID for type inference.
boolean
Throw error if route doesn’t match.Default: true
(search) => any
Select specific search params.

useLoaderData

Access loader data with type safety.

Options

string
Route ID for type inference.
boolean
Throw error if route doesn’t match.Default: true
(data) => any
Select specific data.

useLoaderDeps

Access loader dependencies.

useRouteContext

Access route context.

Options

string
Route ID for type inference.
boolean
Throw error if route doesn’t match.Default: true
(context) => any
Select specific context data.

useMatch

Access a specific route match.

Options

string
Route ID for type inference.
boolean
Throw error if route doesn’t match.Default: true
(match) => any
Select specific match data.

useMatches

Access all current route matches.

Options

(matches: RouteMatch[]) => any
Select specific data from matches.

useParentMatches

Access parent route matches.

useChildMatches

Access child route matches.

useMatchRoute

Check if a route matches.

useBlocker

Block navigation with confirmation.

Options

BlockerFn
required
Function to determine if navigation should be blocked.
boolean | (() => boolean)
Enable browser beforeunload warning.

useCanGoBack

Check if the router can navigate back.

useAwaited

Await deferred promises in components.

Examples

Global Loading State

Authentication Check

Dynamic Title

Form with Unsaved Changes