0
Fork 0
mirror of https://github.com/TanStack/router.git synced 2026-11-18 19:34:24 +00:00
router/docs/framework/react/api/router/rootRouteWithContextFunction.md
Sean Cassiere b5eabe19f5
docs: native markdown relative hyperlinks (#1998)
* docs: reference docs

* docs: guides

* docs: top-level

* docs: missed the route-trees

* docs: fixing routing-concepts
2024-07-20 18:23:45 +12:00

1.5 KiB

id title
rootRouteWithContextFunction rootRouteWithContext function

Caution

This function is deprecated and will be removed in the next major version of TanStack Router. Please use the createRootRouteWithContext function instead.

The rootRouteWithContext 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.

rootRouteWithContext generics

The rootRouteWithContext 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

rootRouteWithContext returns

  • A factory function that can be used to create a new createRootRoute instance.
  • It accepts a single argument, the same as the createRootRoute function.

Examples

import { rootRouteWithContext, createRouter } from '@tanstack/react-router'
import { QueryClient } from '@tanstack/react-query'

interface MyRouterContext {
  queryClient: QueryClient
}

const rootRoute = rootRouteWithContext<MyRouterContext>()({
  component: () => <Outlet />,
  // ... root route options
})

const routeTree = rootRoute.addChildren([
  // ... other routes
])

const queryClient = new QueryClient()

const router = createRouter({
  routeTree,
  context: {
    queryClient,
  },
})