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

__root.tsx

140 lines3.2 KB

1/// <reference types="vite/client" />
2import {
3 HeadContent,
4 Link,
5 Outlet,
6 Scripts,
7 createRootRoute,
8} from '@tanstack/react-router'
9import { TanStackRouterDevtools } from '@tanstack/react-router-devtools'
10import * as React from 'react'
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 }),
55 errorComponent: (props) => {
56 return (
57 <RootLayout>
58 <DefaultCatchBoundary {...props} />
59 </RootLayout>
60 )
61 },
62 notFoundComponent: () => <NotFound />,
63 component: RootComponent,
64})
65​
66function RootComponent() {
67 return (
68 <RootLayout>
69 <Outlet />
70 </RootLayout>
71 )
73​
74function RootLayout({ children }: { children: React.ReactNode }) {
75 return (
76 <html>
77 <head>
78 <HeadContent />
79 </head>
80 <body>
81 <div className="p-2 flex gap-2 text-lg">
82 <Link
83 to="/"
84 activeProps={{
85 className: 'font-bold',
86 }}
87 activeOptions={{ exact: true }}
88 >
89 Home
90 </Link>{' '}
91 <Link
92 to="/posts"
93 activeProps={{
94 className: 'font-bold',
95 }}
96 >
97 Posts
98 </Link>{' '}
99 <Link
100 to="/users"
101 activeProps={{
102 className: 'font-bold',
103 }}
104 >
105 Users
106 </Link>{' '}
107 <Link
108 to="/route-a"
109 activeProps={{
110 className: 'font-bold',
111 }}
112 >
113 Pathless Layout
114 </Link>{' '}
115 <Link
116 to="/deferred"
117 activeProps={{
118 className: 'font-bold',
119 }}
120 >
121 Deferred
122 </Link>{' '}
123 <Link
124 // @ts-expect-error
125 to="/this-route-does-not-exist"
126 activeProps={{
127 className: 'font-bold',
128 }}
129 >
130 This Route Does Not Exist
131 </Link>
132 </div>
133 <hr />
134 {children}
135 <TanStackRouterDevtools position="bottom-right" />
136 <Scripts />
137 </body>
138 </html>
139 )