Open History to see the last commit
1/// <reference types="vite/client" />
2import * as React from 'react'
3import {
4 HeadContent,
5 Link,
6 Outlet,
7 Scripts,
8 createRootRouteWithContext,
9} from '@tanstack/react-router'
10β
11import { DefaultCatchBoundary } from '~/components/DefaultCatchBoundary'
12import { NotFound } from '~/components/NotFound'
13import appCss from '~/styles/app.css?url'
14β
15export const Route = createRootRouteWithContext<{ foo: { bar: string } }>()({
16 head: () => ({
17 meta: [
18 {
19 charSet: 'utf-8',
20 },
21 {
22 name: 'viewport',
23 content: 'width=device-width, initial-scale=1',
24 },
25 ],
26 links: [{ rel: 'stylesheet', href: appCss }],
27 }),
28 errorComponent: (props) => {
29 return (
30 <RootDocument>
31 <DefaultCatchBoundary {...props} />
32 </RootDocument>
33 )
34 },
35 notFoundComponent: () => <NotFound />,
36 component: RootComponent,
37})
38β
39function RootComponent() {
40 return (
41 <RootDocument>
42 <Outlet />
43 </RootDocument>
44 )
45}
46β
47const RouterDevtools =
48 process.env.NODE_ENV === 'production'
49 ? () => null // Render nothing in production
50 : React.lazy(() =>
51 // Lazy load in development
52 import('@tanstack/react-router-devtools').then((res) => ({
53 default: res.TanStackRouterDevtools,
54 })),
55 )
56β
57function RootDocument({ children }: { children: React.ReactNode }) {
58 return (
59 <html>
60 <head>
61 <HeadContent />
62 </head>
63 <body>
64 <div className="p-2 flex gap-2 text-lg">
65 <Link
66 to="/"
67 activeProps={{
68 className: 'font-bold',
69 }}
70 activeOptions={{ exact: true }}
71 >
72 Home
73 </Link>
74 </div>
75 <hr />
76 {children}
77 <RouterDevtools position="bottom-right" />
78 <Scripts />
79 </body>
80 </html>
81 )
82}