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

__root.tsx

131 lines3.1 KB

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