wsimmonds/claude-nextjs-skills/nextjs-dynamic-routes-params
Claude Code and agent skill by wsimmonds/claude-nextjs-skills
- community
Checking that the SKILL.md file is still in the repository.
Guide for Next.js App Router dynamic routes and pathname parameters. Use when building pages that depend on URL segments (IDs, slugs, nested paths), accessing the `params` prop, or fetching resources by identifier. Helps avoid over-nesting by defaulting to the simplest route structure (e.g., `app/[id]` instead of `app/products/[id]` unless the URL calls for it).
Install
npx vskill@latest install wsimmonds/claude-nextjs-skills/nextjs-dynamic-routes-paramsSKILL.md
Next.js Dynamic Routes and Pathname Parameters
When to Use This Skill
Use this skill when:
- Creating dynamic route segments (e.g., blog/[slug], users/[id])
- Accessing URL pathname parameters in Server or Client Components
- Building pages that fetch data based on route parameters
- Implementing catch-all or optional catch-all routes
- Working with the
paramsprop in page.tsx, layout.tsx, or route.ts
⚠️ RECOGNIZING WHEN YOU NEED DYNAMIC ROUTES
Look for requirements that tie data to the URL path.
Create a dynamic segment ([param]) whenever the UI depends on part of the pathname. Typical signals include:
- Details pages that reference “the item’s ID/slug from the URL”
- Copy that calls out path segments (e.g.,
/products/{id},/blog/{slug}) - Requirements to fetch data “based on whichever resource is being visited”
- Navigation flows where one page links to
/something/{identifier}
✅ Dynamic route response
❌ Static-page response
Example requirements that lead to dynamic routes
- “Show a product page that loads whichever product ID appears in the URL” →
app/[id]/page.tsxorapp/products/[id]/page.tsx - “Render a blog article based on its slug” →
app/blog/[slug]/page.tsxorapp/[slug]/page.tsx - “Support nested docs such as /docs/getting-started/installation” →
app/docs/[...slug]/page.tsx
Core rule: If data varies with a URL segment, the folder name needs matching brackets.
⚠️ CRITICAL: Avoid Over-Engineering Route Structure
MOST COMMON MISTAKE: Adding unnecessary nesting to routes.
Default Rule: When creating a dynamic route, use app/[id]/page.tsx or app/[slug]/page.tsx unless:
- The URL structure is explicitly specified (e.g., "create route at /products/[id]")
- You're building multiple resource types that need namespacing
- The requirements clearly show a nested URL structure
Do NOT infer nesting from resource names:
- "Fetch a product by ID" →
app/[id]/page.tsx✅ (notapp/products/[id]) - "Show user profile" →
app/[userId]/page.tsx✅ (notapp/users/[userId]) - "Display blog post" →
app/[slug]/page.tsx✅ (notapp/blog/[slug])
Only nest when explicitly told:
- "Create a route at /blog/[slug]" →
app/blog/[slug]/page.tsx✅ - "Products should be at /products/[id]" →
app/products/[id]/page.tsx✅
Core Concepts
Dynamic Route Syntax
Next.js uses folder names with square brackets to create dynamic route segments:
Key Principle: The folder structure IS the route structure.
Route Structure Decision Tree
CRITICAL RULE: Do NOT infer route structure from resource type names!
Just because you're fetching a "product" or "user" doesn't mean you need /products/[id] or /users/[id]. Unless explicitly told otherwise, prefer the simplest structure.
When deciding on route structure:
- Top-level dynamic route (
app/[id]/page.tsx)
- DEFAULT CHOICE - Use this unless specifically told otherwise
- Use when the resource IS the primary entity
- Use when only ID-based routing is needed
- Examples:
/123for any resource,/abc-deffor slugs - Pattern: The ID/slug is the only identifier needed
- When in doubt, choose this!
- Nested dynamic route (
app/category/[id]/page.tsx)
- ONLY use when explicitly required by the URL structure
- Use when you're told "create a /products/[id] route"
- Use when the URL itself needs the category prefix
- Examples:
/products/123,/blog/my-post(when specified) - Pattern: Category + identifier (when both are required)
- Multi-segment dynamic (
app/[cat]/[id]/page.tsx)
- Use when hierarchy matters
- Examples:
/shop/electronics/123 - Pattern: Multiple levels of categorization
⚠️ COMMON MISTAKE: Creating app/products/[id]/page.tsx when you should create app/[id]/page.tsx
❌ WRONG: "Fetch a product by ID" → app/products/[id]/page.tsx ✅ CORRECT: "Fetch a product by ID" → app/[id]/page.tsx
❌ WRONG: "Create a dynamic route for users" → app/users/[userId]/page.tsx ✅ CORRECT: "Create a dynamic route for users" → app/[userId]/page.tsx
Only add the category prefix when:
- The requirement explicitly says "at /products/..." or similar
- You're building multiple resource types that need namespacing
- The URL structure is specified in requirements
Accessing Pathname Parameters
In Server Components (page.tsx, layout.tsx)
CRITICAL: In Next.js 15+, `params` is a Promise and must be awaited!
For Next.js 14 and earlier:
In Route Handlers (route.ts)
In Client Components
You CANNOT access `params` directly in Client Components. Instead:
- Use `useParams()` hook:
- Pass params from Server Component:
Common Patterns
Pattern 1: Simple ID-Based Page
Pattern 2: Blog Post with Slug
Pattern 3: Nested Resources
Pattern 4: Catch-All Routes
TypeScript Best Practices
Type Safety for Params
Multiple Dynamic Segments
Common Pitfalls and Solutions
Pitfall 1: Forgetting params is a Promise (Next.js 15+)
Pitfall 2: Using params in Client Components without useParams
Pitfall 3: Over-nesting Routes
Pitfall 4: Not Handling Invalid IDs
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingnextjs-dynamic-routes-params/SKILL.md
Popularity
- Repository stars
- 74
- Repository forks
- 9
- 7-day trend score
- 22
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 17 Mar 2026, 7 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/wsimmonds/claude-nextjs-skills/nextjs-dynamic-routes-params)