Skip to main content

React Router

React-specific router implementation with hooks, components, and type-safe navigation.

createRouter

Create a React router instance with type-safe configuration.

RouterProvider

Provides the router instance to your React application.

Props

Router
required
The router instance to provide to the application.
RouteComponent
Default component to render when a route doesn’t specify one.
ErrorRouteComponent
Default error component for the entire application.
RouteComponent
Default pending component for the entire application.
any
Additional context to merge with router context.

Router Class (React)

Extends the core Router with React-specific functionality.

Additional Properties

RouterOptions
The configuration options used to create the router.
Store<RouterState>
Internal reactive store for router state (powered by @tanstack/store).

React-Specific Methods

() => DehydratedRouter
Serialize router state for SSR hydration.
(dehydratedState: DehydratedRouter) => void
Restore router state from dehydrated state.
() => void
Mount the router (called automatically by RouterProvider).
(options: Partial<RouterOptions>) => void
Update router options after creation.

Example: Complete Setup

SSR Setup

Server

Client

Context Management

Type Registration

Register your router for full type safety:
After registration, you’ll get full autocomplete and type checking: