Skip to main content
Routes are the building blocks of your application’s navigation. Each route defines a path pattern, data loading logic, and components to render.

Creating Routes

Routes are created using the createRoute function:

Root Route

Every route tree starts with a root route:

Route Options

Path Configuration

string
required
The path pattern to match. Can include parameters:
string
Custom route ID instead of using the path. Useful for routes without paths.

Components

React.ComponentType
The component to render when this route matches.
React.ComponentType
Component shown while the route is loading data.
React.ComponentType<ErrorComponentProps>
Component shown when an error occurs during loading or rendering.
React.ComponentType
Component shown when a child route is not found.

Search Parameter Validation

Function or validator to parse and validate search parameters.

Path Parameter Parsing

ParseParamsFn
Transform path parameters from strings to typed values.
StringifyParamsFn
Transform typed parameters back to strings for URL generation.

Data Loading

Context

Provide data to child routes and loaders:

Before Load

Run async code before the route loads:

Loader

Fetch data for the route:
Access loader data in components:

Loader Dependencies

Declare additional dependencies for cache keys:

Caching Options

number
default:"0"
Time in milliseconds before cached data is considered stale.
number
default:"1800000"
Time in milliseconds before unused cached data is garbage collected.
number
default:"30000"
How long preloaded data stays fresh.
number
default:"1800000"
How long preloaded data is cached.

Pending State

number
default:"1000"
Delay in milliseconds before showing pending component.
number
default:"500"
Minimum time in milliseconds to show pending component once displayed.

Lifecycle Hooks

onEnter

Called when a route match enters the active matches:

onStay

Called when a route match stays in active matches during navigation:

onLeave

Called when a route match leaves the active matches:

Lazy Loading

Split route components into separate bundles:
In post.lazy.tsx:

SSR Configuration

boolean | 'data-only'
default:"true"
Control server-side rendering behavior:
  • true - Full SSR
  • false - Client-only
  • 'data-only' - SSR data but not component

Meta Tags and Headers

Define meta tags, links, and scripts:

Headers

Set HTTP response headers:

Error Handling

Error Component

onError Hook

Redirects

Redirect from a route using the redirect helper:
Or use the route’s built-in redirect method:

Next Steps

Loaders

Deep dive into data loading patterns

Type Safety

Configure end-to-end type safety

Navigation

Navigate between routes programmatically

Path Params

Extract and validate path parameters