2.1 KiB
description
| description |
|---|
| Create a new Next.js App Router page following project standards |
Create Next.js Frontend Page
Use this workflow when creating a new page in frontend/app/.
Follows specs/05-Engineering-Guidelines/05-03-frontend-guidelines.md, ADR-011, ADR-012, ADR-013, ADR-014.
Steps
-
Determine route — decide the route path, e.g.
app/(dashboard)/documents/page.tsx -
Classify components — decide what is Server Component (default) vs Client Component (
'use client')- Server Component: initial data load, static content, SEO
- Client Component: interactivity, forms, TanStack Query hooks, Zustand
-
Create page file — Server Component by default:
// app/(dashboard)/<route>/page.tsx
import { Metadata } from 'next';
export const metadata: Metadata = {
title: '<Page Title> | LCBP3-DMS',
};
export default async function <PageName>Page() {
return (
<div>
{/* Page content */}
</div>
);
}
- Create API hook (if client-side data needed) — add to
hooks/use-<feature>.ts:
'use client';
import { useQuery } from '@tanstack/react-query';
import { apiClient } from '@/lib/api-client';
export function use<Feature>() {
return useQuery({
queryKey: ['<feature>'],
queryFn: () => apiClient.get('<endpoint>'),
});
}
-
Build UI components — use Shadcn/UI primitives. Place reusable components in
components/<feature>/. -
Handle forms — use React Hook Form + Zod schema validation. Never access form values without validation.
-
Handle errors — add
error.tsxalongsidepage.tsxfor route-level error boundaries. -
Add loading state — add
loading.tsxfor Suspense fallback if page does async work. -
Add to navigation — update sidebar/nav config if the page should appear in the menu.
-
Access control — ensure page checks CASL permissions. Redirect unauthorized users via middleware or
notFound(). -
Citation — confirm implementation references
specs/01-Requirements/andspecs/05-Engineering-Guidelines/05-03-frontend-guidelines.md