---
name: sdlc-nextjs-routing
description: |
Next.js App Router routing primitives: file-based routes, dynamic and catch-all segments, route groups, parallel routes, intercepting routes, middleware, programmatic navigation, link patterns.
Use this skill to:
- Pick the correct dynamic segment syntax for the route shape.
- Use route groups to organize without affecting URLs.
- Implement parallel/intercepting routes for modal-style navigation.
- Build effective middleware for auth, redirects, A/B tests.
- Use Link and useRouter correctly.
Do NOT use this skill for:
- Data fetching per route (see nextjs-data-fetching).
- General file conventions (see nextjs-conventions).
- RSC vs Client (see server-component-patterns).
paths: ["app/**", "pages/**", "src/**"]
---
# Next.js Routing Patterns
App Router is file-based: folders are routes, `page.tsx` is the page UI. This skill covers the routing primitives beyond plain pages.
## Dynamic segments
```
app/users/[id]/page.tsx → /users/:id → params.id: string
app/posts/[slug]/page.tsx → /posts/:slug → params.slug: string
app/docs/[...path]/page.tsx → /docs/a/b/c → params.path: string[]
app/optional/[[...path]]/page.tsx → /optional AND /optional/a/b → params.path: string[] | undefined
```
In Next.js 15+, `params` is a Promise:
```tsx
export default async function Page({ params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
// ...
}
```
In Next.js 14 and earlier, `params` is a plain object — no `await` needed.
## Route groups (organizational)
Folders in parens — DON'T appear in URL but allow:
- Different layouts for different sections.
- Logical organization without nested URLs.
```
app/(marketing)/about/page.tsx → /about
app/(marketing)/pricing/page.tsx → /pricing
app/(marketing)/layout.tsx → applies to /about and /pricing
app/(app)/dashboard/page.tsx → /dashboard
app/(app)/settings/page.tsx → /settings
app/(app)/layout.tsx → applies to /dashboard and /settings
```
`/about` doesn't get the `/(app)/` layout, even though they share `app/`'s root layout.
## Parallel routes
Render two segments simultaneously in one layout — for dashboards, modal overlays, side panels.
```
app/dashboard/layout.tsx
app/dashboard/@analytics/page.tsx → renders into {analytics} slot
app/dashboard/@team/page.tsx → renders into {team} slot
app/dashboard/page.tsx → renders into {children} slot
```
The layout receives all slots:
```tsx
// app/dashboard/layout.tsx
export default function Layout({
children,
analytics,
team,
}: {
children: React.ReactNode;
analytics: React.ReactNode;
team: React.ReactNode;
}) {
return (