Router
The core Router class manages routing state, navigation, and route matching in TanStack Router.RouterOptions
Configuration options for creating a router instance.The root route tree structure that defines all routes in your application.
The history object that manages browser history. If not provided, a new
createBrowserHistory instance will be created.See: History Types GuideThe base path for the router. All routes will be relative to this path.Default:
'/'Function to stringify search params when generating links.Default:
defaultStringifySearchFunction to parse search params when parsing the current location.Default:
defaultParseSearchDefault preloading strategy for routes:
false- Routes are not preloaded'intent'- Preload on hover or touchstart'viewport'- Preload when in viewport'render'- Preload when rendered
falseDelay in milliseconds before preloading a route.Default:
50Default component to render when a route doesn’t have a component defined.
Default error component to render when a route throws an error.
Default pending component to show while a route is loading.
Minimum time in milliseconds to show pending component.Default:
1000Minimum time in milliseconds to keep pending component visible once shown.Default:
500Global context object available to all routes.
How to handle trailing slashes in URLs:
'always'- Always add trailing slash'never'- Always remove trailing slash'preserve'- Keep trailing slash as-is
'never'Where to render the not found component:
'fuzzy'- Render at the nearest parent route'root'- Render at the root route
'fuzzy'Whether route matching should be case-sensitive.Default:
falseRouter Class
Properties
Current router state including location, matches, and status.
The history object managing navigation.
The base path for all routes.
The root route tree structure.
Methods
Navigate to a new location.
Build a location object from navigation options without navigating.
Check if a location matches a route.
Preload a route and its data.
Invalidate and refetch all active route matches.
Load or reload the current route matches.
Subscribe to router events. Returns an unsubscribe function.
RouterState
The current state of the router.The current location object.
Array of matched routes for the current location.
Array of matches that are currently loading.
Current navigation status.
Whether the router is currently loading a route.
Whether the router is currently transitioning between routes.