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

__root.tsx

127 lines3.0 KB

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