// The route tree, shared by the server and the browser. Each side builds its // own router instance from it: the server a per-request memory-history router // (see router.server.ts), the browser a singleton (see router.client.ts). import { createRootRoute, createRoute, createRouter, redirect, type RouterHistory, } from "@octanejs/tanstack-router"; import { Home } from "./routes/Home.tsx"; import { Conversation } from "./routes/Conversation.tsx"; import { Tasks } from "./routes/Tasks.tsx"; import { NotFound } from "./routes/NotFound.tsx"; import { Settings } from "./routes/Settings.tsx"; import { RootLayout } from "./routes/RootLayout.tsx"; /** Key under which the server middleware stores the loaded router in request state. */ export const ROUTER_STATE_KEY = "tanstack.router"; const rootRoute = createRootRoute({ component: RootLayout, notFoundComponent: NotFound, }); const indexRoute = createRoute({ getParentRoute: () => rootRoute, path: "/", component: Home, }); const conversationRoute = createRoute({ getParentRoute: () => rootRoute, path: "conversations/$id", component: Conversation, }); const tasksRoute = createRoute({ getParentRoute: () => rootRoute, path: "tasks", component: Tasks, }); const taskRoute = createRoute({ getParentRoute: () => rootRoute, path: "tasks/$id", component: Tasks, }); // Preserve the old personal-agent entry point without retaining starter content. const agentsRoute = createRoute({ getParentRoute: () => rootRoute, path: "agents", beforeLoad: () => { throw redirect({ to: "/" }); }, }); const settingsRoute = createRoute({ getParentRoute: () => rootRoute, path: "settings", component: Settings, }); const routeTree = rootRoute.addChildren([ indexRoute, conversationRoute, tasksRoute, taskRoute, agentsRoute, settingsRoute, ]); export interface RouterEnv { /** Memory history on the server; omitted in the browser (browser history). */ history?: RouterHistory; /** Use the non-reactive server store factory. */ isServer?: boolean; /** Request origin. Required on the server, where router-core would otherwise read `window`. */ origin?: string; } export function createAppRouter(env: RouterEnv = {}) { return createRouter({ routeTree, history: env.history, isServer: env.isServer, origin: env.origin, defaultPreload: "intent", scrollRestoration: true, }); } export type AppRouter = ReturnType; declare module "@octanejs/tanstack-router" { interface Register { router: AppRouter; } }