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

__root.tsx

62 lines1.4 KB

1import { HeadContent, Scripts, createRootRoute } from '@tanstack/react-router'
2import type { ReactNode } from 'react'
3​
4import Header from '@/components/Header'
5​
6import appCss from '@/styles.css?url'
7​
8const integrationProviders = Object.values(
9 import.meta.glob('../integrations/**/{root-provider,provider}.{ts,tsx}', {
10 eager: true,
11 }),
13 .map((mod) => {
14 const maybeProvider = (mod as { default?: unknown }).default
15 return typeof maybeProvider === 'function' ? maybeProvider : null
16 })
17 .filter((provider): provider is (props: { children: ReactNode }) => ReactNode =>
18 Boolean(provider),
19 )
20​
21export const Route = createRootRoute({
22 head: () => ({
23 meta: [
24 {
25 charSet: 'utf-8',
26 },
27 {
28 name: 'viewport',
29 content: 'width=device-width, initial-scale=1',
30 },
31 {
32 title: 'TanStack Storefront',
33 },
34 ],
35 links: [
36 {
37 rel: 'stylesheet',
38 href: appCss,
39 },
40 ],
41 }),
42 shellComponent: RootDocument,
43})
44​
45function RootDocument({ children }: { children: ReactNode }) {
46 const wrappedChildren = integrationProviders.reduceRight((acc, Provider) => {
47 return <Provider>{acc}</Provider>
48 }, children)
49​
50 return (
51 <html lang="en">
52 <head>
53 <HeadContent />
54 </head>
55 <body>
56 <Header />
57 {wrappedChildren}
58 <Scripts />
59 </body>
60 </html>
61 )