Skip to content
Source
Sign inSign up
fuko/trytanstackdb.com
Open History to see the last commit

router.tsx

31 lines835 Bytes

1import { createRouter } from "@tanstack/react-router";
2import { setupRouterSsrQueryIntegration } from "@tanstack/react-router-ssr-query";
3import * as TanstackQuery from "./integrations/tanstack-query/root-provider";
4​
5// Import the generated route tree
6import { routeTree } from "./routeTree.gen";
7​
8// Create a new router instance
9export const getRouter = () => {
10 const rqContext = TanstackQuery.getContext();
11​
12 const router = createRouter({
13 routeTree,
14 context: { ...rqContext },
15 defaultPreload: "intent",
16 Wrap: (props: { children: React.ReactNode }) => {
17 return (
18 <TanstackQuery.Provider {...rqContext}>
19 {props.children}
20 </TanstackQuery.Provider>
21 );
22 },
23 });
24​
25 setupRouterSsrQueryIntegration({
26 router,
27 queryClient: rqContext.queryClient,
28 });
29​
30 return router;
31};