@tanstack/react-router
Version:
Modern and scalable routing for React applications
1 lines • 3.27 kB
Source Map (JSON)
{"version":3,"file":"RouterProvider.cjs","names":[],"sources":["../../src/RouterProvider.tsx"],"sourcesContent":["'use client'\n\nimport * as React from 'react'\nimport { hasKeys } from '@tanstack/router-core'\nimport { Matches } from './Matches'\nimport { routerContext } from './routerContext'\nimport type {\n AnyRouter,\n RegisteredRouter,\n RouterOptions,\n} from '@tanstack/router-core'\n\n/**\n * Low-level provider that places the router into React context and optionally\n * updates router options from props. Most apps should use `RouterProvider`.\n */\nexport function RouterContextProvider<\n TRouter extends AnyRouter = RegisteredRouter,\n TDehydrated extends Record<string, any> = Record<string, any>,\n>({\n router,\n children,\n ...rest\n}: RouterProps<TRouter, TDehydrated> & {\n children: React.ReactNode\n}) {\n if (hasKeys(rest)) {\n // Allow the router to update options on the router instance\n router.update({\n ...router.options,\n ...rest,\n context: {\n ...router.options.context,\n ...rest.context,\n },\n })\n }\n\n const provider = (\n <routerContext.Provider value={router as AnyRouter}>\n {children}\n </routerContext.Provider>\n )\n\n if (router.options.Wrap) {\n return <router.options.Wrap>{provider}</router.options.Wrap>\n }\n\n return provider\n}\n\n/**\n * Top-level component that renders the active route matches and provides the\n * router to the React tree via context.\n *\n * Accepts the same options as `createRouter` via props to update the router\n * instance after creation.\n *\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/createRouterFunction\n */\nexport function RouterProvider<\n TRouter extends AnyRouter = RegisteredRouter,\n TDehydrated extends Record<string, any> = Record<string, any>,\n>({ router, ...rest }: RouterProps<TRouter, TDehydrated>) {\n return (\n <RouterContextProvider router={router} {...rest}>\n <Matches />\n </RouterContextProvider>\n )\n}\n\nexport type RouterProps<\n TRouter extends AnyRouter = RegisteredRouter,\n TDehydrated extends Record<string, any> = Record<string, any>,\n> = Omit<\n RouterOptions<\n TRouter['routeTree'],\n NonNullable<TRouter['options']['trailingSlash']>,\n NonNullable<TRouter['options']['defaultStructuralSharing']>,\n TRouter['history'],\n TDehydrated\n >,\n 'context'\n> & {\n router: TRouter\n context?: Partial<\n RouterOptions<\n TRouter['routeTree'],\n NonNullable<TRouter['options']['trailingSlash']>,\n NonNullable<TRouter['options']['defaultStructuralSharing']>,\n TRouter['history'],\n TDehydrated\n >['context']\n >\n}\n"],"mappings":";;;;;;;;;;;;;AAgBA,SAAgB,sBAGd,EACA,QACA,UACA,GAAG,QAGF;CACD,KAAA,GAAA,sBAAA,SAAY,IAAI,GAEd,OAAO,OAAO;EACZ,GAAG,OAAO;EACV,GAAG;EACH,SAAS;GACP,GAAG,OAAO,QAAQ;GAClB,GAAG,KAAK;EACV;CACF,CAAC;CAGH,MAAM,WACJ,iBAAA,GAAA,kBAAA,KAAC,sBAAA,cAAc,UAAf;EAAwB,OAAO;EAC5B;CACqB,CAAA;CAG1B,IAAI,OAAO,QAAQ,MACjB,OAAO,iBAAA,GAAA,kBAAA,KAAC,OAAO,QAAQ,MAAhB,EAAA,UAAsB,SAA8B,CAAA;CAG7D,OAAO;AACT;;;;;;;;;;AAWA,SAAgB,eAGd,EAAE,QAAQ,GAAG,QAA2C;CACxD,OACE,iBAAA,GAAA,kBAAA,KAAC,uBAAD;EAA+B;EAAQ,GAAI;YACzC,iBAAA,GAAA,kBAAA,KAAC,gBAAA,SAAD,CAAU,CAAA;CACW,CAAA;AAE3B"}