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'
8import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
9β
10import { Spinner } from './-components/spinner'
11import type { TRPCOptionsProxy } from '@trpc/tanstack-react-query'
12import type { AppRouter } from '../server/trpc'
13import type { QueryClient } from '@tanstack/react-query'
14β
15export interface RouterAppContext {
16 trpc: TRPCOptionsProxy<AppRouter>
17 queryClient: QueryClient
18}
19β
20export const Route = createRootRouteWithContext<RouterAppContext>()({
21 component: RootComponent,
22})
23β
24function RootComponent() {
25 const isFetching = useRouterState({ select: (s) => s.isLoading })
26β
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`}>With tRPC + TanStack Query</h1>
32 {/* Show a global spinner when the router is transitioning */}
33 <div
34 className={`text-3xl duration-300 delay-0 opacity-0 ${
35 isFetching ? ` duration-1000 opacity-40` : ''
36 }`}
37 >
38 <Spinner />
39 </div>
40 </div>
41 <div className={`flex-1 flex`}>
42 <div className={`divide-y w-56`}>
43 {(
44 [
45 ['/', 'Home'],
46 ['/dashboard', 'Dashboard'],
47 ] as const
48 ).map(([to, label]) => {
49 return (
50 <div key={to}>
51 <Link
52 to={to}
53 activeOptions={
54 {
55 // If the route points to the root of it's parent,
56 // make sure it's only active if it's exact
57 // exact: to === '.',
58 }
59 }
60 preload="intent"
61 className={`block py-2 px-3 text-blue-700`}
62 // Make "active" links bold
63 activeProps={{ className: `font-bold` }}
64 >
65 {label}
66 </Link>
67 </div>
68 )
69 })}
70 </div>
71 <div className={`flex-1 border-l border-gray-200`}>
72 {/* Render our first route match */}
73 <Outlet />
74 </div>
75 </div>
76 </div>
77 <TanStackRouterDevtools position="bottom-left" />
78 <ReactQueryDevtools position="bottom" buttonPosition="bottom-right" />
79 </>
80 )
81}