Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

router.tsx

30 lines945 Bytes

1import { QueryClient } from '@tanstack/solid-query'
2import { createRouter } from '@tanstack/solid-router'
3import { setupRouterSsrQueryIntegration } from '@tanstack/solid-router-ssr-query'
4import { routeTree } from './routeTree.gen'
5import { DefaultCatchBoundary } from './components/DefaultCatchBoundary'
6import { NotFound } from './components/NotFound'
7​
8export function getRouter() {
9 const queryClient = new QueryClient({
10 defaultOptions: {
11 queries: {
12 // Enable only on client to avoid hydration mismatches
13 experimental_prefetchInRender: typeof window !== 'undefined',
14 },
15 },
16 })
17 const router = createRouter({
18 routeTree,
19 context: { queryClient },
20 scrollRestoration: true,
21 defaultPreload: 'intent',
22 defaultErrorComponent: DefaultCatchBoundary,
23 defaultNotFoundComponent: () => <NotFound />,
24 })
25 setupRouterSsrQueryIntegration({
26 router,
27 queryClient,
28 })
29 return router