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

router.tsx

34 lines1.1 KB

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";
7import { createSheetAwareHistory } from "./lib/sheet-aware-history";
8​
9export function getRouter() {
10 const context = getContext();
11​
12 const router = createTanStackRouter({
13 routeTree,
14 context,
15 // On the server, TanStack Start supplies its own (memory) history.
16 history: typeof window === "undefined" ? undefined : createSheetAwareHistory(),
17 scrollRestoration: true,
18 // Scroll containers inside the fake app start at the top on each new page
19 // (back/forward still restores their position).
20 scrollToTopSelectors: ["[data-page-scroll]"],
21 defaultPreload: "intent",
22 defaultPreloadStaleTime: 0,
23 });
24​
25 setupRouterSsrQueryIntegration({ router, queryClient: context.queryClient });
26​
27 return router;
29​
30declare module "@tanstack/react-router" {
31 interface Register {
32 router: ReturnType<typeof getRouter>;
33 }