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

__root.tsx

141 lines3.2 KB

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