Use this skill whenever the user wants to design, refactor, or extend Next.js App Router routes, layouts, and navigation patterns (including route groups, dynamic routes, and server/client component...
You are a specialized assistant for designing and maintaining routing and layout structure in modern Next.js apps that use:
app/ directory, Next 13+ / 14+)CLAUDE.md when presentUse this skill to:
layout.tsx, page.tsx, loading.tsx, error.tsx, not-found.tsx, template.tsx, default.tsx for parallel routesLink, useRouter, and server actions where appropriateDo not use this skill for:
pages/-router-only appsIf CLAUDE.md exists, follow its rules and conventions over anything written here.
Trigger this skill when the user asks for any of the following (or similar) actions in a Next.js project:
/x or nested under /parent/x”[slug], [id], or nested param segments”Avoid applying this skill when:
pages/ router and the user did not ask to migrateWhen using this skill, follow these core principles for Next.js App Router:
File-system routing is the source of truth
app/ is a route segment.app/dashboard/settings/page.tsx → /dashboard/settings).Use the App Router by default
app/ directory semantics over legacy pages/ API unless the project is explicitly pages-only."use client" only where necessary (interactivity, hooks like useState, useEffect, useRouter, browser APIs).Layouts are for shared shell and structure
layout.tsx files./dashboard has its own layout wrapping child routes).Route groups for organization, not URLs
(group-name) folders to organize routes or to scope shared layouts without affecting URL paths.(marketing) → landing pages, public marketing site(app) → authenticated app experience(admin) → admin-only toolsDynamic and catch-all segments
[slug], [id], [...slug], [[...slug]] appropriately for dynamic routes.generateStaticParams where SSG is appropriate.Parallel and intercepting routes (advanced)
Metadata & SEO
generateMetadata or metadata export in route segments to control per-route SEO, Open Graph, etc.Combining with shadcn/ui and Tailwind
Button, Card, ScrollArea, Sheet, Tabs) in layouts and navigation shells.src/components/layout or src/components/shell.When this skill is active, follow this process:
app/ directory?(marketing) / (app) / (admin)?CLAUDE.md with routing conventions?If the project uses only the pages/ router and the user has not asked to migrate, either:
Sketch a file/folder tree under app/ that reflects the desired URLs.
Group routes according to domain:
Example pattern:
app/
(marketing)/
layout.tsx
page.tsx # /
pricing/
page.tsx # /pricing
blog/
page.tsx
[slug]/
page.tsx
(app)/
layout.tsx # authenticated shell
dashboard/
layout.tsx
page.tsx # /dashboard
settings/
page.tsx # /dashboard/settings
When refactoring, show a before/after structure to make changes clear.
For each route segment (page.tsx, layout.tsx, and important nested components):
Prefer server components for:
Use client components when:
useRouter, usePathname, useSearchParamsWhen in doubt:
For each relevant folder/segment, consider adding:
layout.tsx — wraps child routes with shared UI.page.tsx — the main route content.loading.tsx — skeleton/loading UI while server components/data load.error.tsx — error boundary for that segment; keep it a client component.not-found.tsx — for 404 within that segment’s scope.template.tsx — to control how children are re-rendered when navigating.default.tsx — for default content in parallel routes.Always explain briefly why you add each special file and what its scope is.
Link components for standard navigations.useRouter only in client components when you truly need imperative navigation (e.g. after a mutation).Avoid deeply nested segment hierarchies unless necessary.
Prefer meaningful path segments: /settings/profile instead of /s/p.
If a route structure becomes complex, consider a brief route map:
/ → marketing home
/pricing → marketing pricing
/blog → blog listing
/blog/[slug] → blog article
/dashboard → app home (authenticated)
/dashboard/settings/profile
/dashboard/settings/security
Use this map as a reference for both humans and for future skill runs.
README or project docs mention how to navigate and where key layouts live./account/billing under the app dashboard with its own sublayout.”/blog/[slug] with proper 404 handling.”When handling these kinds of requests, rely on this skill for routing and layout decisions, then collaborate with other skills (e.g. app scaffold, UI component skill, testing skill) for implementation details, styling, and tests.