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

router.tsx

26 lines724 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'
5​
6export function getRouter() {
7 const queryClient = new QueryClient({
8 defaultOptions: {
9 queries: {
10 // Enable only on client to avoid hydration mismatches
11 experimental_prefetchInRender: typeof window !== 'undefined',
12 },
13 },
14 })
15 const router = createRouter({
16 routeTree,
17 context: { queryClient },
18 scrollRestoration: true,
19 defaultPreload: 'intent',
20 })
21 setupRouterSsrQueryIntegration({
22 router,
23 queryClient,
24 })
25 return router