Documentation Index
Fetch the complete documentation index at: https://mintlify.com/tanstack/router/llms.txt
Use this file to discover all available pages before exploring further.
File Route API
File-based routing APIs for creating routes from the filesystem.createFileRoute
Creates a file-based Route factory for a given path.
Parameters
File path literal for the route (usually auto-generated by the
tsr generator).Returns
A function that accepts Route options and returns a Route instance.The returned function accepts all the same options as
createRoute, including:loader- Load data for the routebeforeLoad- Run before the route loadscomponent- The component to rendererrorComponent- Error boundary componentpendingComponent- Loading componentnotFoundComponent- Not found componentvalidateSearch- Validate search paramsloaderDeps- Loader dependenciesstaleTime- Cache staleness timegcTime- Garbage collection time- And more…
File Route Structure
When using file-based routing, your route files follow a specific naming convention:Standard Routes
Layout Routes
Layout routes don’t add a path segment but wrap child routes:Route Groups
Route groups organize routes without affecting the URL:createLazyFileRoute
Creates a lazily-configurable file-based route stub by file path for code-splitting.
Parameters
File path literal for the route file.
Returns
A function that accepts lazy route options and returns a
LazyRoute.Lazy route options include only non-critical route options:component- The component to renderpendingComponent- Loading componenterrorComponent- Error boundary componentnotFoundComponent- Not found component
Code Splitting Pattern
Split your routes into two files for optimal bundle size:Main Route File
Lazy File
Route File Exports
Route files created withcreateFileRoute can export the following:
Route Export
The route instance created by
createFileRoute. This must be the default export or named Route.