Initialize tanstack/start
This commit is contained in:
7
app/client.tsx
Normal file
7
app/client.tsx
Normal file
@ -0,0 +1,7 @@
|
||||
import { hydrateRoot } from 'react-dom/client'
|
||||
import { StartClient } from '@tanstack/start'
|
||||
import { createRouter } from './router'
|
||||
|
||||
const router = createRouter()
|
||||
|
||||
hydrateRoot(document.getElementById('root')!, <StartClient router={router} />)
|
57
app/routeTree.gen.ts
Normal file
57
app/routeTree.gen.ts
Normal file
@ -0,0 +1,57 @@
|
||||
/* prettier-ignore-start */
|
||||
|
||||
/* eslint-disable */
|
||||
|
||||
// @ts-nocheck
|
||||
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
|
||||
// This file is auto-generated by TanStack Router
|
||||
|
||||
// Import Routes
|
||||
|
||||
import { Route as rootRoute } from './routes/__root'
|
||||
import { Route as IndexImport } from './routes/index'
|
||||
|
||||
// Create/Update Routes
|
||||
|
||||
const IndexRoute = IndexImport.update({
|
||||
path: '/',
|
||||
getParentRoute: () => rootRoute,
|
||||
} as any)
|
||||
|
||||
// Populate the FileRoutesByPath interface
|
||||
|
||||
declare module '@tanstack/react-router' {
|
||||
interface FileRoutesByPath {
|
||||
'/': {
|
||||
id: '/'
|
||||
path: '/'
|
||||
fullPath: '/'
|
||||
preLoaderRoute: typeof IndexImport
|
||||
parentRoute: typeof rootRoute
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create and export the route tree
|
||||
|
||||
export const routeTree = rootRoute.addChildren({ IndexRoute })
|
||||
|
||||
/* prettier-ignore-end */
|
||||
|
||||
/* ROUTE_MANIFEST_START
|
||||
{
|
||||
"routes": {
|
||||
"__root__": {
|
||||
"filePath": "__root.tsx",
|
||||
"children": [
|
||||
"/"
|
||||
]
|
||||
},
|
||||
"/": {
|
||||
"filePath": "index.tsx"
|
||||
}
|
||||
}
|
||||
}
|
||||
ROUTE_MANIFEST_END */
|
16
app/router.tsx
Normal file
16
app/router.tsx
Normal file
@ -0,0 +1,16 @@
|
||||
import { createRouter as createTanStackRouter } from '@tanstack/react-router'
|
||||
import { routeTree } from './routeTree.gen'
|
||||
|
||||
export function createRouter() {
|
||||
const router = createTanStackRouter({
|
||||
routeTree,
|
||||
})
|
||||
|
||||
return router
|
||||
}
|
||||
|
||||
declare module '@tanstack/react-router' {
|
||||
interface Register {
|
||||
router: ReturnType<typeof createRouter>
|
||||
}
|
||||
}
|
43
app/routes/__root.tsx
Normal file
43
app/routes/__root.tsx
Normal file
@ -0,0 +1,43 @@
|
||||
import { createRootRoute } from '@tanstack/react-router'
|
||||
import { Outlet, ScrollRestoration } from '@tanstack/react-router'
|
||||
import { Body, Head, Html, Meta, Scripts } from '@tanstack/start'
|
||||
import * as React from 'react'
|
||||
|
||||
export const Route = createRootRoute({
|
||||
meta: () => [
|
||||
{
|
||||
charSet: 'utf-8',
|
||||
},
|
||||
{
|
||||
name: 'viewport',
|
||||
content: 'width=device-width, initial-scale=1',
|
||||
},
|
||||
{
|
||||
title: 'TanStack Start Starter',
|
||||
},
|
||||
],
|
||||
component: RootComponent,
|
||||
})
|
||||
|
||||
function RootComponent() {
|
||||
return (
|
||||
<RootDocument>
|
||||
<Outlet />
|
||||
</RootDocument>
|
||||
)
|
||||
}
|
||||
|
||||
function RootDocument({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<Html>
|
||||
<Head>
|
||||
<Meta />
|
||||
</Head>
|
||||
<Body>
|
||||
{children}
|
||||
<ScrollRestoration />
|
||||
<Scripts />
|
||||
</Body>
|
||||
</Html>
|
||||
)
|
||||
}
|
14
app/routes/index.tsx
Normal file
14
app/routes/index.tsx
Normal file
@ -0,0 +1,14 @@
|
||||
import { createFileRoute, useRouter } from '@tanstack/react-router'
|
||||
|
||||
export const Route = createFileRoute('/')({
|
||||
component: Home,
|
||||
})
|
||||
|
||||
function Home() {
|
||||
const router = useRouter()
|
||||
const state = Route.useLoaderData()
|
||||
|
||||
return (
|
||||
<h1>Hello World();</h1>
|
||||
)
|
||||
}
|
13
app/ssr.tsx
Normal file
13
app/ssr.tsx
Normal file
@ -0,0 +1,13 @@
|
||||
import {
|
||||
createStartHandler,
|
||||
defaultStreamHandler,
|
||||
} from '@tanstack/start/server'
|
||||
import { getRouterManifest } from '@tanstack/start/router-manifest'
|
||||
|
||||
import { createRouter } from './router'
|
||||
|
||||
export default createStartHandler({
|
||||
createRouter,
|
||||
getRouterManifest,
|
||||
})(defaultStreamHandler)
|
||||
|
Reference in New Issue
Block a user