Skip to content

Black Friday

Annual Pro is $90 for the first year, normally $120. Or start monthly at $6 for two months, then $12.

Ends Dec 4, 11:59 PM PT.

Create an account
← Public packages

@kody/example-habit-log

A small habit log app built from the app starter: indigo theme, mobile layout, sign-in, and saved entries.

FollowFork

Files

router.tsx

37 lines · 1.1 KB · TypeScript
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
	}
}