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

router.tsx

31 lines909 Bytes

1import { createRouter as createTanStackRouter } from "@tanstack/react-router";
2import { routeTree } from "./routeTree.gen";
3​
4import { setupRouterSsrQueryIntegration } from "@tanstack/react-router-ssr-query";
5​
6import { getContext } from "./integrations/tanstack-query/root-provider";
7​
8export function getRouter() {
9 const context = getContext();
10​
11 const router = createTanStackRouter({
12 routeTree,
13 context,
14 scrollRestoration: true,
15 // Scroll containers inside the fake app start at the top on each new page
16 // (back/forward still restores their position).
17 scrollToTopSelectors: ["[data-page-scroll]"],
18 defaultPreload: "intent",
19 defaultPreloadStaleTime: 0,
20 });
21​
22 setupRouterSsrQueryIntegration({ router, queryClient: context.queryClient });
23​
24 return router;
26​
27declare module "@tanstack/react-router" {
28 interface Register {
29 router: ReturnType<typeof getRouter>;
30 }