nextjs-app-router
Installation
SKILL.md
Priority: P0 (CRITICAL)
Implementation Guidelines
Routing Architecture
- Structure: Use the
app/directory. Define routes withapp/dashboard/layout.tsxreturning{children}; shared UI nests insideapp/layout.tsxautomatically. Handle states withloading.tsx,error.tsx, andnot-found.tsx. - Segments: Organize features with Route Groups (brackets
(auth)) to be excluded from URL path. Use Dynamic Routes (brackets[slug]) and define static paths viagenerateStaticParams. - Specialized: Use Parallel Routes (
@modal) by adding the slot to the parent layout and providing adefault.tsxfallback. Use Intercepting Routes ((.)route) for advanced layouts like dashboards.
Data & Functions
- Next.js 15+ Async: Always
awaittheparams: Promise,searchParams,cookies(), andheaders(). - Security: Use
middleware.tsfor edge-side authentication and redirection. Ensure all Route Handlers (route.ts) are secured with appropriate auth checks. - RSC: Default to React Server Components (RSC). Only use
'use client'at leaf nodes for interactivity (hooks/events). - Error Boundaries: Create
app/dashboard/loading.tsxto auto-wrap routes in a Suspense boundary. Inerror.tsx, use'use client'and provide areset: () => voidfunction. const theme = cookieStore.get('theme');