Open History to see the last commit
1import * as React from 'react'
2import {
3 Link,
4 Outlet,
5 createRootRouteWithContext,
6 useRouterState,
7} from '@tanstack/react-router'
8import { TanStackRouterDevtools } from '@tanstack/react-router-devtools'
9import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
10import { Spinner } from '../components/Spinner'
11import type { QueryClient } from '@tanstack/react-query'
12import type { Auth } from '../utils/auth'
13β
14function RouterSpinner() {
15 const isLoading = useRouterState({ select: (s) => s.status === 'pending' })
16 return <Spinner show={isLoading} />
17}
18β
19export const Route = createRootRouteWithContext<{
20 auth: Auth
21 queryClient: QueryClient
22}>()({
23 component: RootComponent,
24})
25β
26function RootComponent() {
27 return (
28 <>
29 <div className={`min-h-screen flex flex-col`}>
30 <div className={`flex items-center border-b gap-2`}>
31 <h1 className={`text-3xl p-2`}>Kitchen Sink</h1>
32 {/* Show a global spinner when the router is transitioning */}
33 <div className={`text-3xl`}>
34 <RouterSpinner />
35 </div>
36 </div>
37 <div className={`flex-1 flex`}>
38 <div className={`divide-y w-56`}>
39 {(
40 [
41 ['/', 'Home'],
42 ['/dashboard', 'Dashboard'],
43 ['/expensive', 'Expensive'],
44 ['/route-a', 'Pathless Layout A'],
45 ['/route-b', 'Pathless Layout B'],
46 ['/profile', 'Profile'],
47 ['/login', 'Login'],
48 ] as const
49 ).map(([to, label]) => {
50 return (
51 <div key={to}>
52 <Link
53 to={to}
54 activeOptions={
55 {
56 // If the route points to the root of it's parent,
57 // make sure it's only active if it's exact
58 // exact: to === '.',
59 }
60 }
61 preload="intent"
62 className={`block py-2 px-3 text-blue-700`}
63 // Make "active" links bold
64 activeProps={{ className: `font-bold` }}
65 >
66 {label}
67 </Link>
68 </div>
69 )
70 })}
71 </div>
72 <div className={`flex-1 border-l`}>
73 <Outlet />
74 </div>
75 </div>
76 </div>
77 <ReactQueryDevtools buttonPosition="top-right" />
78 <TanStackRouterDevtools position="bottom-right" />
79 </>
80 )
81}