Dynamic Routes ([id]), Catch-All Routes ([...slug]) & Route Groups ((group))
Dynamic Routes ([id]), Catch-All Routes ([...slug]) & Route Groups ((group))
In the Next.js App Router, advanced routing patterns are defined using folder naming syntax: Square Brackets [param] for dynamic segments, Ellipses [...slug] for catch-all routes, and Parentheses (group) for organizing code without affecting the URL path.
1. Dynamic Route Segments: [param]
When a URL segment is dynamic (such as a blog post slug or user ID):
- Folder:
app/blog/[slug]/page.tsx - URL:
/blog/learn-nextjs->{ slug: 'learn-nextjs' }
2. Catch-All & Optional Catch-All Routes
1. Catch-All: [...slug]
Matches any number of subsequent path segments and returns them as a string array:
- Folder:
app/docs/[...slug]/page.tsx - Matches:
/docs/getting-started->{ slug: ['getting-started'] } - Matches:
/docs/api/v2/authentication->{ slug: ['api', 'v2', 'authentication'] } - Does NOT match
/docsitself.
2. Optional Catch-All: [[...slug]] (Double Brackets)
Matches all sub-segments AND matches the parent route itself:
- Matches:
/docs->{ slug: undefined } - Matches:
/docs/components/button->{ slug: ['components', 'button'] }
3. Route Groups: (groupName)
Route Groups allow organizing folders and sharing specific layouts without affecting the URL path:
Notice that neither (marketing) nor (dashboard) appears in the browser URL!
Multiple Choice Questions
params and search searchParams be consumed inside an async Server Component page.tsx?/shop AND any deeply nested path like /shop/clothing/jackets/winter?app/(auth)/login/page.tsx?app/tutorials/[...slug]/page.tsx, what will (await params).slug evaluate to when a user visits /tutorials/web/react/hooks?(marketing)/about/page.tsx and (admin)/about/page.tsx)?Streaming UI with loading.tsx and Suspense Boundaries
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Related Lessons
Practice Quiz
Test your understanding of this lesson with 5 questions. Each question has one correct answer.