Open History to see the last commit
1import { routerContext } from './routerContext'
2import { SafeFragment } from './SafeFragment'
3import { Matches } from './Matches'
4import type {
5 AnyRouter,
6 RegisteredRouter,
7 RouterOptions,
8} from '@tanstack/router-core'
9import type * as Solid from 'solid-js'
10β
11export function RouterContextProvider<
12 TRouter extends AnyRouter = RegisteredRouter,
13 TDehydrated extends Record<string, any> = Record<string, any>,
14>({
15 router,
16 children,
17 ...rest
18}: RouterProps<TRouter, TDehydrated> & {
19 children: () => Solid.JSX.Element
20}) {
21 // Allow the router to update options on the router instance
22 router.update({
23 ...router.options,
24 ...rest,
25 context: {
26 ...router.options.context,
27 ...rest.context,
28 },
29 })
30β
31 const OptionalWrapper = router.options.Wrap || SafeFragment
32β
33 return (
34 <OptionalWrapper>
35 <routerContext.Provider value={router as AnyRouter}>
36 {children()}
37 </routerContext.Provider>
38 </OptionalWrapper>
39 )
40}
41β
42export function RouterProvider<
43 TRouter extends AnyRouter = RegisteredRouter,
44 TDehydrated extends Record<string, any> = Record<string, any>,
45>({ router, ...rest }: RouterProps<TRouter, TDehydrated>) {
46 return (
47 <RouterContextProvider router={router} {...rest}>
48 {() => <Matches />}
49 </RouterContextProvider>
50 )
51}
52β
53export type RouterProps<
54 TRouter extends AnyRouter = RegisteredRouter,
55 TDehydrated extends Record<string, any> = Record<string, any>,
56> = Omit<
57 RouterOptions<
58 TRouter['routeTree'],
59 NonNullable<TRouter['options']['trailingSlash']>,
60 false,
61 TRouter['history'],
62 TDehydrated
63 >,
64 'context' | 'pathParamsAllowedCharacters'
65> & {
66 router: TRouter
67 context?: Partial<
68 RouterOptions<
69 TRouter['routeTree'],
70 NonNullable<TRouter['options']['trailingSlash']>,
71 false,
72 TRouter['history'],
73 TDehydrated
74 >['context']
75 >
76}