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

__root.tsx.ejs

106 lines3.7 KB

1<% if (!fileRouter) { ignoreFile() } %>import { <% if (addOnEnabled.start) { %>
2 HeadContent<% } else { %>Outlet<% } %><% if (addOnEnabled.start) { %>, Scripts<% } %>, <% if (addOnEnabled["tanstack-query"]) { %>createRootRouteWithContext<% } else { %>createRootRoute<% } %> } from '@tanstack/react-router'
3import { TanStackRouterDevtoolsPanel } from '@tanstack/react-router-devtools';
4import { TanStackDevtools } from '@tanstack/react-devtools'
5<% if (addOns.length) { %>
6import Header from '../components/Header'
7<% } %><% for(const integration of integrations.filter(i => i.type === 'layout' || i.type === 'provider' || i.type === 'devtools')) { %>
8import <%= integration.jsName %> from '<%= relativePath(integration.path, true) %>'
9<% } %>
10<% if (addOnEnabled.start) { %>
11import appCss from '../styles.css?url'
12<% } %><% if (addOnEnabled["tanstack-query"]) { %>
13import type { QueryClient } from '@tanstack/react-query'
14<% if (addOnEnabled.tRPC) { %>
15import type { TRPCRouter } from '@/integrations/trpc/router'
16import type { TRPCOptionsProxy } from '@trpc/tanstack-react-query'
17<% } %>
18​
19interface MyRouterContext {
20 queryClient: QueryClient
21 <% if (addOnEnabled.tRPC) { %>
22 trpc: TRPCOptionsProxy<TRPCRouter>
23 <% } %>
24}<% } %>
26export const Route = <% if (addOnEnabled["tanstack-query"]) { %>createRootRouteWithContext<MyRouterContext>()<% } else { %>createRootRoute<% } %>({
27<% if (addOnEnabled.start) { %>
28 head: () => ({
29 meta: [
30 {
31 charSet: 'utf-8',
32 },
33 {
34 name: 'viewport',
35 content: 'width=device-width, initial-scale=1',
36 },
37 {
38 title: 'TanStack Start Starter',
39 },
40 ],
41 links: [
42 {
43 rel: 'stylesheet',
44 href: appCss,
45 },
46 ],
47 }),
48<% } %>
49<% if (addOnEnabled.start) { %>
50 shellComponent: RootDocument
51<% } else { %>
52 component: () => (
53 <>
54 <% for(const integration of integrations.filter(i => i.type === 'provider')) { %><<%= integration.jsName %>>
55 <% } %><% if (addOns.length) { %><Header />
56 <% } %><Outlet />
57 <TanStackDevtools
58 config={{
59 position: 'bottom-right',
60 }}
61 plugins={[
62 {
63 name: 'Tanstack Router',
64 render: <TanStackRouterDevtoolsPanel />,
65 },
66 <% for(const integration of integrations.filter(i => i.type === 'devtools')) { %><%= integration.jsName %>,<% } %>
67 ]}
68 />
69 <% for(const integration of integrations.filter(i => i.type === 'layout')) { %><<%= integration.jsName %> />
70 <% } %><% for(const integration of integrations.filter(i => i.type === 'provider').reverse()) { %></<%= integration.jsName %>>
71 <% } %>
72 </>)
73<% } %>
74})
75​
76<% if (addOnEnabled.start) { %>
77function RootDocument({ children }: { children: React.ReactNode }) {
78 return (
79 <html lang="en">
80 <head>
81 <HeadContent />
82 </head>
83 <body>
84 <% for(const integration of integrations.filter(i => i.type === 'provider')) { %><<%= integration.jsName %>>
85 <% } %><% if (addOns.length) { %><Header />
86 <% } %>{children}
87 <TanStackDevtools
88 config={{
89 position: 'bottom-right',
90 }}
91 plugins={[
92 {
93 name: 'Tanstack Router',
94 render: <TanStackRouterDevtoolsPanel />,
95 },
96 <% for(const integration of integrations.filter(i => i.type === 'devtools')) { %><%= integration.jsName %>,<% } %>
97 ]}
98 />
99 <% for(const integration of integrations.filter(i => i.type === 'layout')) { %><<%= integration.jsName %> />
100 <% } %><% for(const integration of integrations.filter(i => i.type === 'provider').reverse()) { %></<%= integration.jsName %>>
101 <% } %><Scripts />
102 </body>
103 </html>
104 )
106<% } %>