Creating Routes
Routes are created using thecreateRoute 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
SearchValidator
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: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:post.lazy.tsx:
SSR Configuration
boolean | 'data-only'
default:"true"
Control server-side rendering behavior:
true- Full SSRfalse- Client-only'data-only'- SSR data but not component
Meta Tags and Headers
Head
Define meta tags, links, and scripts:Headers
Set HTTP response headers:Error Handling
Error Component
onError Hook
Redirects
Redirect from a route using theredirect helper:
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