← Public packages
@kody/example-reading-list
A small reading list app built from the app starter: warm theme, mobile layout, sign-in, and saved books.
Files
import { createRouter, type RouterHistory } from '@tanstack/react-router'
import type { RouterContext } from './router-context.ts'
import { accountRoute } from './routes/account.tsx'
import { indexRoute } from './routes/index.tsx'
import { itemsRoute } from './routes/items.tsx'
import { rootRoute } from './routes/root.tsx'
/** Add a route file under app/routes, then list it here. */
const routeTree = rootRoute.addChildren([indexRoute, itemsRoute, accountRoute])
export function createAppRouter(input: {
history: RouterHistory
context: RouterContext
/** The request origin. Required on the server, where there is no window. */
origin?: string
}) {
const basepath = input.context.appBasePath.replace(/\/+$/, '')
return createRouter({
routeTree,
history: input.history,
context: input.context,
origin: input.origin,
isServer: input.origin !== undefined,
basepath: basepath || undefined,
defaultPreload: 'intent',
defaultPendingMs: 300,
})
}
declare module '@tanstack/react-router' {
interface Register {
router: ReturnType<typeof createAppRouter>
}
interface StaticDataRouteOption {
title?: string
}
}