Agent-skills-standard nextjs-app-router
Configure file-system routing with nested layouts, route groups, parallel routes, and error boundaries in Next.js App Router. Use when creating page routes, adding loading/error states, or organizing routes with groups and dynamic segments. (triggers: app/**/page.tsx, app/**/layout.tsx, app/**/loading.tsx, App Router, Layout, Route Group, parallel routes)
install
source · Clone the upstream repo
git clone https://github.com/HoangNguyen0403/agent-skills-standard
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/HoangNguyen0403/agent-skills-standard "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/nextjs/nextjs-app-router" ~/.claude/skills/hoangnguyen0403-agent-skills-standard-nextjs-app-router && rm -rf "$T"
manifest:
skills/nextjs/nextjs-app-router/SKILL.mdsource content
Priority: P0 (CRITICAL)
Workflow: Add New Route
- Create page — Add
as Server Component.app/dashboard/page.tsx - Add layout — Create
returningapp/dashboard/layout.tsx
.{children} - Add loading state — Create
for Suspense boundary.app/dashboard/loading.tsx - Add error boundary — Create
withapp/dashboard/error.tsx
and'use client'
prop.reset - Await async APIs — In Next.js 15+,
,await params
,cookies()
.headers()
Route Group Example
Implementation Guidelines
Routing Architecture
- Structure: Use
directory. Define routes withapp/
returningapp/dashboard/layout.tsx
; shared UI nests inside{children}
automatically. Handle states withapp/layout.tsx
,loading.tsx
, anderror.tsx
.not-found.tsx - Segments: Organize features with Route Groups (brackets
) to excluded from URL path. Use Dynamic Routes (brackets(auth)
) and define static paths via[slug]
.generateStaticParams - Specialized: Use Parallel Routes (
) by adding slot to parent layout and providing@modal
fallback. Use Intercepting Routes (default.tsx
) for advanced layouts like dashboards.(.)route
Data & Functions
- Next.js 15+ Async: Always
await
,params: Promise
,searchParams
, andcookies()
.headers() - Security: Use
for edge-side authentication and redirection. Ensure all Route Handlers (middleware.ts
) secured with appropriate auth checks.route.ts - RSC: Default to React Server Components (RSC). Only use
at leaf nodes for interactivity (hooks/events).'use client' - Error Boundaries: Create
to auto-wrap routes in Suspense boundary. Inapp/dashboard/loading.tsx
, useerror.tsx
and provide'use client'
function.reset: () => void
File Conventions
- page.tsx: UI for route.
- layout.tsx: Shared UI wrapping children. Persists across navigation.
- loading.tsx: Suspense boundary for loading states.
- error.tsx: Error boundary (Must Client Component).
- route.ts: Server-side API endpoint.
Structure Patterns
- Route Groups: Use parenthesis
to organize without affecting URL path.(auth) - Private Folders: Use underscore
to exclude from routing._lib - Dynamic Routes: Use brackets
or[slug]
(catch-all).[...slug]
Best Practices
- RSC Boundaries: Ensure props passed to Client Components serializable. See RSC Boundaries & Serialization.
- Parallel Routes (
): Render multiple pages in same layout. Use@folder
for fallback.default.tsx - Intercepting Routes (
): Load routes within current layout context.(..)folder - Colocation: Keep component files, styles, and tests inside route folder.
- Layouts: Use Root Layout (
) forapp/layout.tsx
and<html>
tags.<body> - Self-Hosting Standard
Anti-Patterns
- No unawaited async APIs:
,params
,cookies()
Promises in Next.js 15+; always await.headers() - No
at tree root: Place at leaves; keep layouts and pages as Server Components.'use client' - No
/<html>
in nested layouts: Only<body>
(root layout) should include them.app/layout.tsx - No missing
: Every route segment needs Client Component error boundary.error.tsx