Skip to main content

Route

Routes define the structure of your application and handle data loading, rendering, and error handling.

Route Options

Configuration options for creating a route.
string
The path pattern for the route. Supports path params using $param syntax.
string
Custom route ID. If not provided, generated from the path.
() => Route
required
Function that returns the parent route.
RouteComponent
Component to render for this route.
ErrorRouteComponent
Component to render when the route throws an error.
RouteComponent
Component to render while the route is loading.
NotFoundRouteComponent
Component to render when a child route is not found.
LoaderFn
Function to load data for the route.
BeforeLoadFn
Function that runs before the loader. Useful for authentication and redirects.
Validator for search parameters. Can use Zod, Valibot, or custom validators.
ParamsOptions
Configuration for parsing and stringifying path params.
RouteContextFn
Function to create additional context for this route and its children.
(error: Error) => void
Error boundary handler for the route.
(error: Error) => void
Called when the route encounters an error.
Record<string, any>
Static metadata for the route (e.g., for generating sitemaps).
number
Time in milliseconds before cached loader data is considered stale.Default: 0
number
Time in milliseconds before inactive cached data is garbage collected.Default: 30 minutes
boolean
Whether to preload this route’s data.Default: true
number
Time in milliseconds before preloaded data is considered stale.

Route Class

Properties

string
The unique identifier for this route.
string
The path pattern for this route.
string
The complete path including all parent paths.
RouteOptions
The configuration options for this route.

Methods

(children: Route[]) => Route
Add child routes to this route.
(options: PartialRouteOptions) => Route
Update route options.

Creating Routes

Root Route

Every router needs a root route:

Standard Routes

File-based Routes

Loader Context

The loader function receives a context object:
Record<string, any>
Path parameters extracted from the URL.
Validated search parameters.
AnyContext
Combined context from parent routes and global context.
ParsedLocation
The current location object.
AbortController
Controller to cancel ongoing async operations.
boolean
Whether this loader is being called for preloading.

Route Hooks

Routes provide hooks for accessing route-specific data:

Route Masking

Create virtual routes that display different content:

Example: Complete Route