Mount the application router
Application bootstrap
TanStack · Component
RouterProvider mounts a configured TanStack Router in a React application. Pass the router instance through its router prop, usually at the application root.
RouterProvider is the React component that mounts a configured TanStack Router into the component tree. Pass the router instance created with createRouter through the router prop, typically rendering the provider as the application root.
<RouterProvider router={router} />| Name | Type | Description |
|---|---|---|
router | Router | The configured TanStack Router instance that RouterProvider mounts for the React application. |
A React element that provides TanStack Router functionality to its descendant component tree.
import { RouterProvider, createRouter } from '@tanstack/react-router'
import { routeTree } from './routeTree.gen'
const router = createRouter({ routeTree })
export default function App() {
return <RouterProvider router={router} />
}Create a router from the generated route tree, then render it through RouterProvider at the application root.
Application bootstrap
React Query integration
Generated routes
RouterProvider renders the configured router for a React application. It receives the router instance through its router prop, as in <RouterProvider router={router} />.
Follow-up: How would you combine it with TanStack Query? Render QueryClientProvider around RouterProvider so both providers are available to the application.
First create a router with the application's route tree, then pass that instance to RouterProvider. The documented example imports RouterProvider and Router, constructs the router, and renders the provider.
Follow-up: Why use a generated route tree? It supplies the route structure consumed when configuring the router.
RouterProvider belongs at the application rendering boundary, where it can mount the router for the React tree. The official example exports an App component whose returned JSX is RouterProvider.
Follow-up: What commonly surrounds it in an application? A query client provider may wrap it when using React Query, as shown in the official integration example.
createRouterRouterQueryClientProviderrouteTree