File tree Expand file tree Collapse file tree 1 file changed +23
-2
lines changed Expand file tree Collapse file tree 1 file changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -10,19 +10,40 @@ import {
1010 createRootRoute ,
1111 createRoute ,
1212 createRouter ,
13+ matchContext ,
14+ useRouterState ,
1315} from "@tanstack/react-router" ;
1416
1517const rootRoute = createRootRoute ( ) ;
16- const index = createRoute ( { getParentRoute : ( ) => rootRoute , path : "/" } ) ;
18+ const index = createRoute ( {
19+ getParentRoute : ( ) => rootRoute ,
20+ path : "/" ,
21+ component : ( ) => null ,
22+ } ) ;
1723
1824const router = createRouter ( {
1925 history : createMemoryHistory ( ) ,
2026 routeTree : rootRoute . addChildren ( [ index ] ) ,
2127} ) ;
28+ router . load ( ) ;
29+
30+ const InnerProvider : React . FC < React . PropsWithChildren > = ( { children } ) => {
31+ const matchId = useRouterState ( {
32+ select : ( s ) => {
33+ return s . matches [ 0 ] ?. id ;
34+ } ,
35+ } ) ;
36+
37+ return (
38+ < matchContext . Provider value = { matchId } > { children } </ matchContext . Provider >
39+ ) ;
40+ } ;
2241
2342export const DummyRouter : React . FC < React . PropsWithChildren > = ( {
2443 children,
2544} ) => (
2645 /** @ts -expect-error: The router we pass doesn't match the "real" router, which is fine for tests */
27- < RouterContextProvider router = { router } > { children } </ RouterContextProvider >
46+ < RouterContextProvider router = { router } >
47+ < InnerProvider > { children } </ InnerProvider >
48+ </ RouterContextProvider >
2849) ;
You can’t perform that action at this time.
0 commit comments