Pages, Routes and Layouts
Generate a page, understand file-based routing, add translated labels and a sidebar link, and choose a layout.
Create app pages with the kit generator. It adds the session check, translated document title, and application-shell components for you.
1. Generate a Signed-in Page
From the repository root:
pnpm kit:generate page account-summary/indexThis creates:
apps/web/pages/(app)/account-summary/ index.server.ts loader, actions, document title, exported Props type index.tsx React page componentOpen /account-summary in your running app. (app) is a route group: it organizes files and selects the app shell without adding a segment to the URL. Signed-out visitors are redirected to sign-in.
The generator is create-only. If a destination already exists, it refuses the operation rather than replacing your code. See Generators for other supported paths and package scaffolding.
2. Add the Page's Labels
Merge these keys into apps/web/messages/en/app.json; keep the existing keys:
{ "accountSummary": { "title": "Account summary", "name": "Display name", "email": "Email address", "save": "Save name", "saving": "Saving…", "saved": "Your name was updated.", "failed": "Your name could not be saved. Please try again.", "tooManyChanges": "Please wait before changing your name again." }}For this hyphenated path, the generator uses the camel-cased title key accountSummary.title. In server code, getServerTranslator({ c, namespace: 'app' }) reads it with t('accountSummary.title'). In React, useTranslations('app.accountSummary') reads it with t('title').
Use the app translation MCP tools when working with an agent. Add the same keys for other enabled locales. See Managing Translations.
3. Load and Display the Current User's Name
Keep the generated head export and use this loader in index.server.ts:
import { defineHandler, defineHead, type InferProps } from 'void';import { getServerTranslator } from '#/lib/i18n.server.ts';import { requireSession } from '#/lib/session.server.ts';export const loader = defineHandler((c) => { const { user } = requireSession({ c }); return { name: user.name };});export type Props = InferProps<typeof loader>;export const head = defineHead((c) => { const t = getServerTranslator({ c, namespace: 'app' }); return { title: t('accountSummary.title') };});Render the props in index.tsx:
import { useTranslations } from '@kit/i18n/react';import { Heading } from '@kit/ui/heading';import { PageBody } from '@kit/ui/page';import { AppPageHeader } from '#/components/app-page-header.tsx';import type { Props } from './index.server';export default function AccountSummaryPage({ name }: Props) { const t = useTranslations('app.accountSummary'); return ( <> <AppPageHeader /> <PageBody> <Heading level={2}>{t('title')}</Heading> <p>{name}</p> </PageBody> </> );}Props follows the loader's return type. Change the loader's data and TypeScript shows which parts of the component need updating.
4. Add a Sidebar Link
In apps/web/config/navigation.config.tsx, add an item to the existing application array:
{ label: 'app.accountSummary.title', path: '/account-summary', Icon: <Home className={iconClasses} />,},That file already imports Home and defines iconClasses. Choose another Lucide icon if you want. Adding a link controls discovery; the server still checks access in the loader and every action. See Navigation.
Routing Patterns
| File | URL |
|---|---|
pages/(app)/account-summary/index.tsx | /account-summary |
pages/(app)/reports/[id].tsx | /reports/123 |
pages/help/[...slug].tsx | /help/getting-started/install |
pages/about.tsx | /about |
Read a dynamic parameter in server code with c.req.param('id'). Validate it before passing it to a service. Use bracket patterns in typed links:
import { Link } from '@void/react';<Link href="/reports/[id]" params={{ id: report.id }}> {report.name}</Link>This link example assumes you generated a reports/[id] page and have a report object. Quote bracket paths in your terminal: pnpm kit:generate page 'reports/[id]'.
Public Pages and Layouts
pnpm kit:generate page about --public creates a public page outside (app)/. Public marketing links use the kit's LocalizedLink to preserve locale prefixes; see Internationalization. Auth pages and marketing pages with their own special layouts follow their existing folders' conventions.
The root pages/layout.tsx supplies shared providers. pages/(app)/layout.tsx supplies the application sidebar. A nested layout.tsx wraps a subtree, and a named layout in pages/_layouts/ can be selected with export const layout = 'settings', as the kit's settings pages do. Layouts preserve state while navigating within them.
Do not add 'use client' or Next.js Server Component conventions to Void pages. The page component can use React hooks; its .server.ts companion owns server work.