Skip to content
Source
Sign inSign up
fuko/trytanstackdb.com
Open History to see the last commit

__root.tsx

74 lines2.4 KB

1import { HeadContent, Outlet, Scripts, createRootRouteWithContext } from "@tanstack/react-router";
2import { TanStackRouterDevtoolsPanel } from "@tanstack/react-router-devtools";
3import { TanStackDevtools } from "@tanstack/react-devtools";
4import type { QueryClient } from "@tanstack/react-query";
5import type { ReactNode } from "react";
6​
7import { AppNotifications } from "../components/shell/app-notifications";
8import TanStackQueryDevtools from "../integrations/tanstack-query/devtools";
9import { themeInitScript } from "../lib/theme";
10import appCss from "../styles.css?url";
11​
12interface MyRouterContext {
13 queryClient: QueryClient;
15​
16export const Route = createRootRouteWithContext<MyRouterContext>()({
17 head: () => ({
18 meta: [
19 { charSet: "utf-8" },
20 { name: "viewport", content: "width=device-width, initial-scale=1, viewport-fit=cover" },
21 { title: "Try TanStack DB — an interactive guide" },
22 {
23 name: "description",
24 content: "Learn TanStack DB by using a notes app next to the guide that explains it.",
25 },
26 ],
27 links: [
28 { rel: "stylesheet", href: appCss },
29 { rel: "apple-touch-icon", sizes: "180x180", href: "/apple-touch-icon.png" },
30 { rel: "icon", type: "image/png", sizes: "32x32", href: "/favicon-32x32.png" },
31 { rel: "icon", type: "image/png", sizes: "16x16", href: "/favicon-16x16.png" },
32 { rel: "manifest", href: "/site.webmanifest" },
33 ],
34 }),
35 shellComponent: RootDocument,
36 component: RootLayout,
37});
38​
39/**
40 * Shared by every page. Rollback toasts and guide progress live here, not in
41 * the Notes app: a change can settle after the reader has moved on to a
42 * deep dive, and they should still hear about it.
43 */
44function RootLayout() {
45 return (
46 <>
47 <Outlet />
48 <AppNotifications />
49 </>
50 );
52​
53function RootDocument({ children }: { children: ReactNode }) {
54 return (
55 <html lang="en" suppressHydrationWarning>
56 <head>
57 {/* Sets the light/dark class before first paint. */}
58 <script dangerouslySetInnerHTML={{ __html: themeInitScript }} />
59 <HeadContent />
60 </head>
61 <body>
62 {children}
63 <TanStackDevtools
64 config={{ position: "bottom-right", hideUntilHover: true }}
65 plugins={[
66 { name: "Tanstack Router", render: <TanStackRouterDevtoolsPanel /> },
67 TanStackQueryDevtools,
68 ]}
69 />
70 <Scripts />
71 </body>
72 </html>
73 );