Open History to see the last commit
1import {
2 Link,
3 Outlet,
4 createRootRouteWithContext,
5 useRouterState,
6} from '@tanstack/react-router'
7import { TanStackRouterDevtools } from '@tanstack/react-router-devtools'
8β
9import { Spinner } from './-components/spinner'
10import type { trpc } from '../trpc'
11β
12export interface RouterAppContext {
13 trpc: typeof trpc
14}
15β
16export const Route = createRootRouteWithContext<RouterAppContext>()({
17 component: RootComponent,
18})
19β
20function RootComponent() {
21 const isFetching = useRouterState({ select: (s) => s.isLoading })
22β
23 return (
24 <>
25 <div className={`min-h-screen flex flex-col`}>
26 <div className={`flex items-center border-b gap-2`}>
27 <h1 className={`text-3xl p-2`}>With tRPC</h1>
28 {/* Show a global spinner when the router is transitioning */}
29 <div
30 className={`text-3xl duration-300 delay-0 opacity-0 ${
31 isFetching ? ` duration-1000 opacity-40` : ''
32 }`}
33 >
34 <Spinner />
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 ] as const
44 ).map(([to, label]) => {
45 return (
46 <div key={to}>
47 <Link
48 to={to}
49 activeOptions={
50 {
51 // If the route points to the root of it's parent,
52 // make sure it's only active if it's exact
53 // exact: to === '.',
54 }
55 }
56 preload="intent"
57 className={`block py-2 px-3 text-blue-700`}
58 // Make "active" links bold
59 activeProps={{ className: `font-bold` }}
60 >
61 {label}
62 </Link>
63 </div>
64 )
65 })}
66 </div>
67 <div className={`flex-1 border-l border-gray-200`}>
68 {/* Render our first route match */}
69 <Outlet />
70 </div>
71 </div>
72 </div>
73 <TanStackRouterDevtools position="bottom-right" />
74 </>
75 )
76}