Creating Routes
createRoute
Creates a non-root Route instance for code-based routing.
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.
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.
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.
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 matchuseRouteContext(opts?)- Access route contextuseSearch(opts?)- Access search paramsuseParams(opts?)- Access path paramsuseLoaderDeps(opts?)- Access loader depsuseLoaderData(opts?)- Access loader datauseNavigate()- Get navigate functionLink- Pre-bound Link componentnotFound(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
useRouteContext
useSearch
useParams
useLoaderData
useLoaderDeps
useNavigate
Link
Component Types
RouteComponent
A standard route component.
packages/react-router/src/route.tsx:682
ErrorRouteComponent
Component for rendering errors.
packages/react-router/src/route.tsx:684
NotFoundRouteComponent
Component for 404 errors.
packages/react-router/src/route.tsx:686