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 createRootRoute,
9} from '@tanstack/react-router'
10β
11import { DefaultCatchBoundary } from '~/components/DefaultCatchBoundary'
12import { NotFound } from '~/components/NotFound'
13import appCss from '~/styles/app.css?url'
14import { seo } from '~/utils/seo'
15β
16export const Route = createRootRoute({
17 head: () => ({
18 meta: [
19 {
20 charSet: 'utf-8',
21 },
22 {
23 name: 'viewport',
24 content: 'width=device-width, initial-scale=1',
25 },
26 ...seo({
27 title:
28 'TanStack Start | Type-Safe, Client-First, Full-Stack React Framework',
29 description: `TanStack Start is a type-safe, client-first, full-stack React framework. `,
30 }),
31 ],
32 links: [
33 { rel: 'stylesheet', href: appCss },
34 {
35 rel: 'apple-touch-icon',
36 sizes: '180x180',
37 href: '/apple-touch-icon.png',
38 },
39 {
40 rel: 'icon',
41 type: 'image/png',
42 sizes: '32x32',
43 href: '/favicon-32x32.png',
44 },
45 {
46 rel: 'icon',
47 type: 'image/png',
48 sizes: '16x16',
49 href: '/favicon-16x16.png',
50 },
51 { rel: 'manifest', href: '/site.webmanifest', color: '#fffff' },
52 { rel: 'icon', href: '/favicon.ico' },
53 ],
54 styles: [
55 {
56 media: 'all and (min-width: 500px)',
57 children: `
58 .inline-div {
59 color: white;
60 background-color: gray;
61 max-width: 250px;
62 }`,
63 },
64 ],
65 }),
66 errorComponent: (props) => {
67 return (
68 <RootDocument>
69 <DefaultCatchBoundary {...props} />
70 </RootDocument>
71 )
72 },
73 notFoundComponent: () => <NotFound />,
74 component: RootComponent,
75})
76β
77function RootComponent() {
78 return (
79 <RootDocument>
80 <Outlet />
81 </RootDocument>
82 )
83}
84β
85const RouterDevtools =
86 process.env.NODE_ENV === 'production'
87 ? () => null // Render nothing in production
88 : React.lazy(() =>
89 // Lazy load in development
90 import('@tanstack/react-router-devtools').then((res) => ({
91 default: res.TanStackRouterDevtools,
92 })),
93 )
94β
95function RootDocument({ children }: { children: React.ReactNode }) {
96 return (
97 <html>
98 <head>
99 <HeadContent />
100 </head>
101 <body>
102 <div className="p-2 flex gap-2 text-lg">
103 <Link
104 to="/"
105 activeProps={{
106 className: 'font-bold',
107 }}
108 activeOptions={{ exact: true }}
109 >
110 Home
111 </Link>{' '}
112 <Link
113 to="/posts"
114 activeProps={{
115 className: 'font-bold',
116 }}
117 >
118 Posts
119 </Link>{' '}
120 <Link
121 to="/users"
122 activeProps={{
123 className: 'font-bold',
124 }}
125 >
126 Users
127 </Link>{' '}
128 <Link
129 to="/layout-a"
130 activeProps={{
131 className: 'font-bold',
132 }}
133 >
134 Layout
135 </Link>{' '}
136 <Link
137 to="/scripts"
138 activeProps={{
139 className: 'font-bold',
140 }}
141 >
142 Scripts
143 </Link>{' '}
144 <Link
145 to="/inline-scripts"
146 activeProps={{
147 className: 'font-bold',
148 }}
149 >
150 Inline Scripts
151 </Link>{' '}
152 <Link
153 to="/deferred"
154 activeProps={{
155 className: 'font-bold',
156 }}
157 >
158 Deferred
159 </Link>{' '}
160 <Link
161 to="/redirect"
162 activeProps={{
163 className: 'font-bold',
164 }}
165 >
166 redirect
167 </Link>{' '}
168 <Link
169 // @ts-expect-error
170 to="/this-route-does-not-exist"
171 activeProps={{
172 className: 'font-bold',
173 }}
174 >
175 This Route Does Not Exist
176 </Link>
177 </div>
178 <hr />
179 {children}
180 <div className="inline-div">This is an inline styled div</div>
181 <React.Suspense fallback={null}>
182 <RouterDevtools position="bottom-right" />
183 </React.Suspense>
184 <Scripts />
185 </body>
186 </html>
187 )
188}