Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

__root.tsx

130 lines3.1 KB

1import {
2 HeadContent,
3 Link,
4 Scripts,
5 createRootRoute,
6} from '@tanstack/react-router'
7import { TanStackRouterDevtools } from '@tanstack/react-router-devtools'
8import * as React from 'react'
9import { DefaultCatchBoundary } from '~/components/DefaultCatchBoundary'
10import { NotFound } from '~/components/NotFound'
11import appCss from '~/styles/app.css?url'
12import { seo } from '~/utils/seo'
13​
14export const Route = createRootRoute({
15 head: () => ({
16 meta: [
17 {
18 charSet: 'utf-8',
19 },
20 {
21 name: 'viewport',
22 content: 'width=device-width, initial-scale=1',
23 },
24 ...seo({
25 title:
26 'TanStack Start | Type-Safe, Client-First, Full-Stack React Framework',
27 description: `TanStack Start is a type-safe, client-first, full-stack React framework. `,
28 }),
29 ],
30 links: [
31 { rel: 'stylesheet', href: appCss },
32 {
33 rel: 'apple-touch-icon',
34 sizes: '180x180',
35 href: '/apple-touch-icon.png',
36 },
37 {
38 rel: 'icon',
39 type: 'image/png',
40 sizes: '32x32',
41 href: '/favicon-32x32.png',
42 },
43 {
44 rel: 'icon',
45 type: 'image/png',
46 sizes: '16x16',
47 href: '/favicon-16x16.png',
48 },
49 { rel: 'manifest', href: '/site.webmanifest', color: '#fffff' },
50 { rel: 'icon', href: '/favicon.ico' },
51 ],
52 scripts: [
53 {
54 src: '/customScript.js',
55 type: 'text/javascript',
56 },
57 ],
58 }),
59 errorComponent: DefaultCatchBoundary,
60 notFoundComponent: () => <NotFound />,
61 shellComponent: RootDocument,
62})
63​
64function RootDocument({ children }: { children: React.ReactNode }) {
65 return (
66 <html>
67 <head>
68 <HeadContent />
69 </head>
70 <body>
71 <div className="p-2 flex gap-2 text-lg">
72 <Link
73 to="/"
74 activeProps={{
75 className: 'font-bold',
76 }}
77 activeOptions={{ exact: true }}
78 >
79 Home
80 </Link>{' '}
81 <Link
82 to="/posts"
83 activeProps={{
84 className: 'font-bold',
85 }}
86 >
87 Posts
88 </Link>{' '}
89 <Link
90 to="/users"
91 activeProps={{
92 className: 'font-bold',
93 }}
94 >
95 Users
96 </Link>{' '}
97 <Link
98 to="/route-a"
99 activeProps={{
100 className: 'font-bold',
101 }}
102 >
103 Pathless Layout
104 </Link>{' '}
105 <Link
106 to="/deferred"
107 activeProps={{
108 className: 'font-bold',
109 }}
110 >
111 Deferred
112 </Link>{' '}
113 <Link
114 // @ts-expect-error
115 to="/this-route-does-not-exist"
116 activeProps={{
117 className: 'font-bold',
118 }}
119 >
120 This Route Does Not Exist
121 </Link>
122 </div>
123 <hr />
124 {children}
125 <TanStackRouterDevtools position="bottom-right" />
126 <Scripts />
127 </body>
128 </html>
129 )