Skip to main content

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

string
required
File path literal for the route (usually auto-generated by the tsr generator).

Returns

Function
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 route
  • beforeLoad - Run before the route loads
  • component - The component to render
  • errorComponent - Error boundary component
  • pendingComponent - Loading component
  • notFoundComponent - Not found component
  • validateSearch - Validate search params
  • loaderDeps - Loader dependencies
  • staleTime - Cache staleness time
  • gcTime - 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

string
required
File path literal for the route file.

Returns

Function
A function that accepts lazy route options and returns a LazyRoute.Lazy route options include only non-critical route options:
  • component - The component to render
  • pendingComponent - Loading component
  • errorComponent - Error boundary component
  • notFoundComponent - 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 with createFileRoute can export the following:

Route Export

Route
required
The route instance created by createFileRoute. This must be the default export or named Route.

Path Parameters

Define path parameters in your file names:

Single Parameter

Multiple Parameters

Splat/Catch-all

Search Parameter Validation

Validate and type search parameters:

Route Context

Add context to a route and its children:
Child routes can access this context: