Skip to main content
Routes define the structure of your application, including paths, components, loaders, and validation logic.

Creating Routes

createRoute

Creates a non-root Route instance for code-based routing.
Source: packages/react-router/src/route.tsx:330-410
RouteOptions
required
Route configuration options.
Route
A Route instance to be attached to the route tree.

createRootRoute

Creates a root Route instance used to build your route tree.
Source: packages/react-router/src/route.tsx:605-657
RootRouteOptions
Root route configuration options (similar to RouteOptions but without path or parent).
RootRoute
A root route instance.

createRootRouteWithContext

Creates a root route factory that requires a router context type.
Source: packages/react-router/src/route.tsx:435-470
() => RootRoute
A factory function to configure and return a root route with typed context.

Route API

getRouteApi

Returns a route-specific API that exposes type-safe hooks pre-bound to a single route ID.
Source: packages/react-router/src/route.tsx:90-95
RouteId
required
Route ID string literal for the target route.
RouteApi
A RouteApi instance bound to the given route ID with methods:
  • useMatch(opts?) - Access the route match
  • useRouteContext(opts?) - Access route context
  • useSearch(opts?) - Access search params
  • useParams(opts?) - Access path params
  • useLoaderDeps(opts?) - Access loader deps
  • useLoaderData(opts?) - Access loader data
  • useNavigate() - Get navigate function
  • Link - Pre-bound Link component
  • notFound(opts?) - Throw not-found error

Route Class

The Route class provides route-specific hooks and components. Source: packages/react-router/src/route.tsx:170-317

Instance Methods

Each Route instance has the following methods:

useMatch

Returns the current route match with params, search, loader data, and more.

useRouteContext

Returns the route’s context object.

useSearch

Returns the route’s validated search parameters.

useParams

Returns the route’s path parameters.

useLoaderData

Returns the route’s loader data.

useLoaderDeps

Returns the route’s loader dependencies.

useNavigate

Returns a navigate function pre-bound to the route’s path.
A Link component pre-bound to the route’s path.

Component Types

RouteComponent

A standard route component.
Can be a regular component or lazy-loaded:
Source: packages/react-router/src/route.tsx:682

ErrorRouteComponent

Component for rendering errors.
Receives error and reset props:
Source: packages/react-router/src/route.tsx:684

NotFoundRouteComponent

Component for 404 errors.
Source: packages/react-router/src/route.tsx:686

Usage Examples

Basic Route

Route with Params

Route with Loader

Route with Search Validation

Route with Error Handling

See Also