Route API
Routes define the URL structure, data loading, and rendering for your application.
createRoute
Creates a non-root Route instance for code-based routing.
Parameters
Route configuration options.
A function that returns the parent route. Required for non-root routes.
The path segment for this route. Can include path parameters like $postId.
A custom ID for the route. If not provided, one will be generated from the path.
The component to render for this route.
The component to render when an error occurs in this route.
The component to render while the route is loading.
The component to render when this route doesn’t match.
A function that loads data for the route. A function that is called before the route is loaded. Can be used for authentication checks. A function or schema to validate and parse search parameters. (opts: { search }) => any
A function that returns dependencies for the loader. Changes trigger a reload. A function that returns additional context for this route and its children. The time in milliseconds that the route’s data will be considered fresh.
The time in milliseconds that the route’s data will be kept in the cache after it becomes unused.
The minimum time in milliseconds before the pending component is shown.
The minimum time in milliseconds that the pending component will be shown once it appears.
If true, this route will be preloaded when it enters the viewport or on intent.
The time in milliseconds that preloaded data will be considered fresh.
boolean | ((args) => boolean)
Controls whether the route should reload when navigated to.
Returns
A Route instance to be attached to the route tree.
Route Methods
Route instances expose several type-safe methods for use in components:
route.useMatch()
Get the current route match data.
route.useParams()
Access the route’s path parameters.
route.useSearch()
Access the route’s search parameters.
route.useLoaderData()
Access the route’s loader data.
route.useLoaderDeps()
Access the route’s loader dependencies.
route.useNavigate()
Get a navigate function pre-bound to this route.
route.useRouteContext()
Access the route’s context.
route.Link
A pre-bound Link component for this route.
createRouteMask
Create a route mask for displaying a route at a different path.
Parameters
The route tree to create the mask for.
The route path to mask from.
The route path to mask to (what will be shown in the URL).
Parameters to include in the masked URL. Use true to include all params.
Search parameters to include in the masked URL. Use true to include all search params.
Hash to include in the masked URL. Use true to include the current hash.
If true, the mask will be removed when the page is reloaded.
Returns
A route mask object to pass to the router’s routeMasks option.
Component Types
RouteComponent
A standard route component type.
ErrorRouteComponent
An error boundary component type with error props.
NotFoundRouteComponent
A not-found component type with routing props.