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

__root.tsx

85 lines1.9 KB

1/// <reference types="vite/client" />
2import {
3 HeadContent,
4 Outlet,
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: 'TanStack Website',
27 description: `TanStack projects are type-safe!!!`,
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 }),
53 errorComponent: (props) => {
54 return (
55 <RootDocument>
56 <DefaultCatchBoundary {...props} />
57 </RootDocument>
58 )
59 },
60 notFoundComponent: () => <NotFound />,
61 component: RootComponent,
62})
63​
64function RootComponent() {
65 return (
66 <RootDocument>
67 <Outlet />
68 </RootDocument>
69 )
71​
72function RootDocument({ children }: { children: React.ReactNode }) {
73 return (
74 <html>
75 <head>
76 <HeadContent />
77 </head>
78 <body>
79 {children}
80 <TanStackRouterDevtools position="bottom-right" />
81 <Scripts />
82 </body>
83 </html>
84 )