Open History to see the last commit
1import { render } from 'solid-js/web'
2import { RouterProvider, createRouter } from '@tanstack/solid-router'
3import { routeTree } from './routeTree.gen'
4import './styles.css'
5β
6// Set up a Router instance
7const router = createRouter({
8 routeTree,
9 defaultPreload: 'intent',
10 defaultStaleTime: 5000,
11 scrollRestoration: true,
12 /*
13 Using defaultViewTransition would prevent the need to
14 manually add `viewTransition: true` to every navigation.
15β
16 If defaultViewTransition.types is a function, it will be called with the
17 location change info and should return an array of view transition types.
18 This is useful if you want to have different view transitions depending on
19 the navigation's specifics.
20β
21 An example use case is sliding in a direction based on the index of the
22 previous and next routes when navigating via browser history back and forth.
23 */
24 // defaultViewTransition: true
25 // OR
26 // defaultViewTransition: {
27 // types: ({ fromLocation, toLocation }) => {
28 // let direction = 'none'
29β
30 // if (fromLocation) {
31 // const fromIndex = fromLocation.state.__TSR_index
32 // const toIndex = toLocation.state.__TSR_index
33β
34 // direction = fromIndex > toIndex ? 'right' : 'left'
35 // }
36β
37 // return [`slide-${direction}`]
38 // },
39 // },
40})
41β
42// Register things for typesafety
43declare module '@tanstack/solid-router' {
44 interface Register {
45 router: typeof router
46 }
47}
48β
49const rootElement = document.getElementById('app')!
50β
51if (!rootElement.innerHTML) {
52 render(() => <RouterProvider router={router} />, rootElement)
53}