'use client' import * as React from 'react' import { Matches } from './Matches' import { routerContext } from './routerContext' import type { AnyRouter, RegisteredRouter, RouterOptions, } from '@tanstack/router-core' /** * Low-level provider that places the router into React context and optionally * updates router options from props. Most apps should use `RouterProvider`. */ export function RouterContextProvider< TRouter extends AnyRouter = RegisteredRouter, TDehydrated extends Record = Record, >({ router, children, ...rest }: RouterProps & { children: React.ReactNode }) { if (Object.keys(rest).length > 0) { // Allow the router to update options on the router instance router.update({ ...router.options, ...rest, context: { ...router.options.context, ...rest.context, }, }) } const provider = ( {children} ) if (router.options.Wrap) { return {provider} } return provider } /** * Top-level component that renders the active route matches and provides the * router to the React tree via context. * * Accepts the same options as `createRouter` via props to update the router * instance after creation. * * @link https://tanstack.com/router/latest/docs/framework/react/api/router/createRouterFunction */ export function RouterProvider< TRouter extends AnyRouter = RegisteredRouter, TDehydrated extends Record = Record, >({ router, ...rest }: RouterProps) { return ( ) } export type RouterProps< TRouter extends AnyRouter = RegisteredRouter, TDehydrated extends Record = Record, > = Omit< RouterOptions< TRouter['routeTree'], NonNullable, NonNullable, TRouter['history'], TDehydrated >, 'context' > & { router: TRouter context?: Partial< RouterOptions< TRouter['routeTree'], NonNullable, NonNullable, TRouter['history'], TDehydrated >['context'] > }