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