Open History to see the last commit
1/// <reference types="vite/client" />
2import {
3 ClientOnly,
4 HeadContent,
5 Link,
6 Outlet,
7 Scripts,
8 createRootRoute,
9 useRouterState,
10} from '@tanstack/solid-router'
11β
12import { TanStackRouterDevtoolsInProd } from '@tanstack/solid-router-devtools'
13import { HydrationScript } from 'solid-js/web'
14import { NotFound } from '~/components/NotFound'
15import '~/styles/app.css'
16import { seo } from '~/utils/seo'
17β
18export const Route = createRootRoute({
19 head: () => ({
20 meta: [
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 {
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 styles: [
53 {
54 media: 'all and (min-width: 500px)',
55 children: `
56 .inline-div {
57 color: white;
58 background-color: gray;
59 max-width: 250px;
60 }`,
61 },
62 ],
63 }),
64 errorComponent: (props) => <p>{props.error.stack}</p>,
65 notFoundComponent: () => <NotFound />,
66 component: RootComponent,
67})
68β
69function RootComponent() {
70 const routerState = useRouterState({
71 select: (state) => ({ isLoading: state.isLoading, status: state.status }),
72 })
73β
74 return (
75 <html>
76 <head>
77 <HydrationScript />
78 </head>
79 <body>
80 <HeadContent />
81 <div class="p-2 flex gap-2 text-lg">
82 <Link
83 to="/"
84 activeProps={{
85 class: 'font-bold',
86 }}
87 activeOptions={{ exact: true }}
88 >
89 Home
90 </Link>{' '}
91 <Link
92 to="/posts"
93 activeProps={{
94 class: 'font-bold',
95 }}
96 >
97 Posts
98 </Link>{' '}
99 <Link
100 to="/users"
101 activeProps={{
102 class: 'font-bold',
103 }}
104 >
105 Users
106 </Link>{' '}
107 <Link
108 to="/layout-a"
109 activeProps={{
110 class: 'font-bold',
111 }}
112 >
113 Layout
114 </Link>{' '}
115 <Link
116 to="/scripts"
117 activeProps={{
118 class: 'font-bold',
119 }}
120 >
121 Scripts
122 </Link>{' '}
123 <Link
124 to="/inline-scripts"
125 activeProps={{
126 class: 'font-bold',
127 }}
128 >
129 Inline Scripts
130 </Link>{' '}
131 <Link
132 to="/deferred"
133 activeProps={{
134 class: 'font-bold',
135 }}
136 >
137 Deferred
138 </Link>{' '}
139 <Link
140 to="/redirect"
141 activeProps={{
142 class: 'font-bold',
143 }}
144 >
145 redirect
146 </Link>{' '}
147 <Link
148 to="/raw-stream"
149 activeProps={{
150 class: 'font-bold',
151 }}
152 >
153 Raw Stream
154 </Link>{' '}
155 <Link
156 // @ts-expect-error
157 to="/this-route-does-not-exist"
158 activeProps={{
159 class: 'font-bold',
160 }}
161 >
162 This Route Does Not Exist
163 </Link>
164 </div>
165 <ClientOnly>
166 <div hidden>
167 <b data-testid="router-isLoading">
168 {routerState().isLoading ? 'true' : 'false'}
169 </b>
170 <b data-testid="router-status">{routerState().status}</b>
171 </div>
172 </ClientOnly>
173 <Outlet />
174 <div class="inline-div">This is an inline styled div</div>
175 <TanStackRouterDevtoolsInProd />
176 <Scripts />
177 </body>
178 </html>
179 )
180}