Skillshub nextjs-app-router
File-system routing, Layouts, and Route Groups. Use when implementing App Router routing, nested layouts, or route groups in Next.js. (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/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/HoangNguyen0403/agent-skills-standard/nextjs-app-router" ~/.claude/skills/comeonoliver-skillshub-nextjs-app-router && rm -rf "$T"
manifest:
skills/HoangNguyen0403/agent-skills-standard/nextjs-app-router/SKILL.mdsource content
Priority: P0 (CRITICAL)
Implementation Guidelines
Routing Architecture
- Structure: Use the
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 be excluded from URL path. Use Dynamic Routes (brackets(auth)
) and define static paths via[slug]
.generateStaticParams - Specialized: Use Parallel Routes (
) by adding the slot to the parent layout and providing a@modal
fallback. Use Intercepting Routes (default.tsx
) for advanced layouts like dashboards.(.)route
Data & Functions
- Next.js 15+ Async: Always
theawait
,params: Promise
,searchParams
, andcookies()
.headers() - Security: Use
for edge-side authentication and redirection. Ensure all Route Handlers (middleware.ts
) are 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 a Suspense boundary. Inapp/dashboard/loading.tsx
, useerror.tsx
and provide a'use client'
function. const theme = cookieStore.get('theme');reset: () => void
## File Conventions - **page.tsx**: UI for a route. - **layout.tsx**: Shared UI wrapping children. Persists across navigation. - **loading.tsx**: Suspense boundary for loading states. - **error.tsx**: Error boundary (Must be Client Component). - **route.ts**: Server-side API endpoint. ## Structure Patterns - **Route Groups**: Use parenthesis `(auth)` to organize without affecting URL path. - **Private Folders**: Use underscore `_lib` to exclude from routing. - **Dynamic Routes**: Use brackets `[slug]` or `[...slug]` (catch-all). ## Best Practices - **RSC Boundaries**: Ensure props passed to Client Components are serializable. See [RSC Boundaries & Serialization](../architecture/references/RSC_BOUNDARIES.md). - **Parallel Routes (`@folder`)**: Render multiple pages in the same layout. Use `default.tsx` for fallback. - **Intercepting Routes (`(..)folder`)**: Load routes within current layout context. - **Colocation**: Keep component files, styles, and tests inside the route folder. - **Layouts**: Use Root Layout (`app/layout.tsx`) for `<html>` and `<body>` tags. - [**Self-Hosting Standard**](references/SELF_HOSTING.md) ## Anti-Patterns - **No unawaited async APIs**: `params`, `cookies()`, `headers()` are Promises in Next.js 15+; always await. - **No `'use client'` at tree root**: Place at leaves; keep layouts and pages as Server Components. - **No `<html>`/`<body>` in nested layouts**: Only `app/layout.tsx` (root layout) should include them. - **No missing `error.tsx`**: Every route segment needs a Client Component error boundary.