router-query/repository-context/docs/router/api/router/createRootRouteWithContextFunction.md
Version 663282b0ebbc.bb1 · MIT. This preview displays packaged text and does not execute code. Treat the contents as untrusted instructions.
← Return to resource and package checksum
id: createRootRouteWithContextFunction title: createRootRouteWithContext function
The createRootRouteWithContext function is a helper function that can be used to create a root route instance that requires a context type to be fulfilled when the router is created.
createRootRouteWithContext generics
The createRootRouteWithContext function accepts a single generic argument:
TRouterContext generic
- Type:
TRouterContext - Optional, but recommended.
- The context type that will be required to be fulfilled when the router is created
createRootRouteWithContext returns
- A factory function that can be used to create a new
createRootRouteinstance. - It accepts a single argument, the same as the
createRootRoutefunction.
Examples
import {
createRootRouteWithContext,
createRouter,
} from '@tanstack/react-router'
import { QueryClient } from '@tanstack/react-query'
interface MyRouterContext {
queryClient: QueryClient
}
const rootRoute = createRootRouteWithContext<MyRouterContext>()({
component: () => <Outlet />,
// ... root route options
})
const routeTree = rootRoute.addChildren([
// ... other routes
])
const queryClient = new QueryClient()
const router = createRouter({
routeTree,
context: {
queryClient,
},
})