Skip to main content
TanStack Router provides several built-in components for rendering routes, handling navigation, and managing errors.

Core Components

Outlet

Renders the child route’s component in a parent route layout.
The Outlet component is the React Router equivalent of rendering child routes. It should be placed in parent route components where you want child routes to appear.

RouterProvider

Top-level component that renders the active route matches and provides the router to the React tree.
Source: packages/react-router/src/RouterProvider.tsx:58-67
TRouter
required
The router instance created with createRouter.
Partial<RouterOptions>
Additional options to update the router. Accepts same options as createRouter.
Strongly-typed anchor component for declarative navigation.
See the Link API documentation for full details. Component that triggers navigation when rendered.
Source: packages/react-router/src/useNavigate.tsx:54-78
string
required
Destination route path.
TParams
Path parameters for the destination.
Search parameters for the destination.
string
URL hash for the destination.
boolean
default:"false"
Replace current history entry instead of pushing.
boolean
default:"true"
Reset scroll position on navigation.
null
Renders nothing, navigation happens in an effect.

Matching Components

MatchRoute

Component that conditionally renders its children based on whether a route matches.
Source: packages/react-router/src/Matches.tsx:201-216
string
required
Route path to match against.
TParams
Specific params to match.
TSearch
Specific search params to match.
boolean
default:"false"
Allow fuzzy matching (partial path match).
boolean
default:"false"
Match against pending location instead of current.
boolean
default:"false"
Match paths case-sensitively.
React.ReactNode | (params) => React.ReactNode
Content to render when matched. If a function, receives the matched params.

Error Handling Components

CatchBoundary

Internal error boundary component used by routes to catch rendering errors.
Source: packages/react-router/src/CatchBoundary.tsx:5-29
() => number | string
required
Function returning a key that resets the error boundary when changed.
ErrorRouteComponent
default:"ErrorComponent"
Component to render when an error is caught.
(error: Error, errorInfo: ErrorInfo) => void
Callback when an error is caught.
React.ReactNode
required
Content to render (protected by the boundary).

ErrorComponent

Default error component that displays error information.
Source: packages/react-router/src/CatchBoundary.tsx:80-121
Error
required
The error that was caught.
() => void
Function to reset the error boundary and retry.
The default ErrorComponent shows:
  • Error message
  • Toggle to show/hide details
  • In development: full error details
  • In production: minimal error message

CatchNotFound

Error boundary specifically for handling not-found errors.
Source: packages/react-router/src/not-found.tsx:8-39
(error: NotFoundError) => React.ReactElement
Component to render when a not-found error is caught.
(error: Error, errorInfo: ErrorInfo) => void
Callback when a not-found error is caught.
React.ReactNode
required
Content to render (protected by the boundary).

Blocker Components

Block

Component that blocks navigation based on a condition.
Source: packages/react-router/src/useBlocker.tsx:286-306
(args: BlockerArgs) => boolean | Promise<boolean>
required
Function to determine if navigation should be blocked.
boolean | (() => boolean)
default:"true"
Enable browser’s beforeunload warning.
boolean
default:"false"
Disable the blocker.
boolean
default:"false"
Provide resolver to children for handling blocked navigation.
React.ReactNode | (resolver) => React.ReactNode
Content to render. If a function and withResolver is true, receives blocker resolver.

Usage Examples

Layout with Outlet

Conditional Navigation

Conditional Rendering

Custom Error Handling

Not Found Handling

Form with Navigation Blocker

Multi-Level Layout

Best Practices

Always Use Outlet

Every parent route that has children should render an Outlet:

Error Boundaries at Strategic Levels

Place error boundaries at logical boundaries in your app:

Use Navigate for Redirects

Use the Navigate component for declarative redirects:

Combine MatchRoute with Logic

Use MatchRoute for conditional UI based on routes:

See Also