nextjs-dynamic-routes-params▌
wsimmonds/claude-nextjs-skills · updated Apr 8, 2026
MDX-style export adds YAML metadata + attribution linking explainx.ai and this canonical listing URL.
Use this skill when:
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
Requirement: display product information based on whichever ID appears in the URL
Implementation: app/[id]/page.tsx
Access parameter with: const { id } = await params;
❌ Static-page response
Implementation: app/page.tsx ← cannot access per-path identifiers
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:
app/
├── [id]/page.tsx # Matches /123, /abc, etc.
├── blog/[slug]/page.tsx # Matches /blog/hello-world
├── shop/[category]/[id]/page.tsx # Matches /shop/electronics/123
└── docs/[...slug]/page.tsx # Matches /docs/a, /docs/a/b, /docs/a/b/c
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!
// ✅ CORRECT - Next.js 15+
export default async function ProductPage({
params,
}: {
params: Promise<{ id: string }>;
}) {
const { id } = await params;
const product = await fetch(`https://api.example.com/products/${id}`)
.then(res => res.json());
return <div>{product.name}</div>;
}
// ❌ WRONG - Treating params as synchronous object (Next.js 15+)
export default async function ProductPage({
params,
}: {
params: { id: string }; // Missing Promise wrapper
}) {
const product = await fetch(`https://api.example.com/products/${params.id}`);
// This will fail because params is a Promise!
}
For Next.js 14 and earlier:
// Next.js 14 - params is synchronous
export default async function ProductPage({
params,
}: {
params: { id: string };
}) {
const product = await fetch(`https://api.example.com/products/${params.id}`)
.then(res => res.json());
return <div>{product.name}</div>;
}
In Route Handlers (route.ts)
// app/api/products/[id]/route.ts
export async function GET(
request: Request,
{ params }: { params: Promise<{ id: string }> }
) {
const { id } = await params;
const product = await db.products.findById(id);
return Response.json(product);
}
In Client Components
You CANNOT access params directly in Client Components. Instead:
- Use
useParams()hook:
'use client';
import { useParams } from 'next/navigation';
export function ProductClient() {
const params = useParams<{ id: string }>();
const id = params.id;
// Use the id...
}
- Pass params from Server Component:
// app/products/[id]/page.tsx (Server Component)
export default async function ProductPage({
params,
}: {
params: Promise<{ id: string }>;
}) {
const { id } = await params;
return <ProductClient productId={id} />;
}
// components/ProductClient.tsx
'use client';
export function ProductClient({ productId }: { productId: string }) {
// Use productId...
}
Common Patterns
Pattern 1: Simple ID-Based Page
// app/[id]/page.tsx - Top-level dynamic route
interface PageProps {
params: Promise<{ id: string }>;
}
export how to use nextjs-dynamic-routes-paramsHow to use nextjs-dynamic-routes-params on Cursor
AI-first code editor with Composer
1Prerequisites
Before installing skills in Cursor, ensure your development environment meets these requirements:
- ›Cursor installed and configured on your development machine
- ›Node.js version 16.0+ with npm package manager (verify with
node --version) - ›Active project directory or workspace where you want to add nextjs-dynamic-routes-params
2Execute installation command
Execute the skills CLI command in your project's root directory to begin installation:
$npx skills add https://github.com/wsimmonds/claude-nextjs-skills --skill nextjs-dynamic-routes-paramsThe skills CLI fetches nextjs-dynamic-routes-params from GitHub repository wsimmonds/claude-nextjs-skills and configures it for Cursor.
3Select Cursor when prompted
The CLI will show a list of available agents. Use arrow keys to navigate and space to select Cursor:
◆ Which agents do you want to install to?││ ── Universal (.agents/skills) ── always included ────│ • Amp│ • Antigravity│ • Cline│ • Codex│ ●Cursor(selected)│ • Cursor│ • Windsurf4Verify installation
Confirm successful installation by checking the skill directory location:
.cursor/skills/nextjs-dynamic-routes-paramsReload or restart Cursor to activate nextjs-dynamic-routes-params. Access the skill through slash commands (e.g., /nextjs-dynamic-routes-params) or your agent's skill management interface.
⚠Security & Verification Notice
We perform automated surface-level scans (Gen AI Scanner, Socket, Snyk) during installation. These checks detect common vulnerabilities but do not guarantee complete security. Always review skill source code and verify the publisher's reputation before production use.
Skills execute code in your development environment. Always verify the publisher's identity, review recent commits, and test in isolated environments before production deployment.
Additional Resources
List & Monetize Your Skill
Submit your Claude Code skill and start earning
GET_STARTED →Use Cases▌
Task Automation & Efficiency
Automate repetitive workflows and reduce manual effort
Example
Generate reports, summarize documents, draft communications
✓Save 3-5 hours per week on routine tasks
Knowledge Enhancement
Learn new skills, understand complex topics, get expert guidance
Example
Explain concepts, provide examples, suggest learning resources
✓Accelerate learning and skill development by 2x
Quality Improvement
Enhance output quality through reviews, suggestions, and refinements
Example
Review drafts, suggest improvements, catch errors
✓Improve work quality by 30-40% with less effort
Implementation Guide▌
Prerequisites
- ›Claude Desktop or compatible AI client with skill support
- ›Clear understanding of task or problem to solve
- ›Willingness to iterate and refine outputs
Time Estimate
15-45 minutes depending on use case complexity
Installation Steps
- 1.Install skill using provided installation command
- 2.Test with simple use case relevant to your work
- 3.Evaluate output quality and relevance
- 4.Iterate on prompts to improve results
- 5.Integrate into regular workflow if valuable
Common Pitfalls
- ⚠Expecting perfect results without iteration
- ⚠Not providing enough context in prompts
- ⚠Using skill for tasks outside its intended scope
- ⚠Accepting outputs without review and validation
Best Practices▌
✓ Do
- +Start with clear, specific prompts
- +Provide relevant context and constraints
- +Review and refine all outputs before using
- +Iterate to improve output quality
- +Document successful prompt patterns
✗ Don't
- −Don't use without understanding skill limitations
- −Don't skip validation of outputs
- −Don't share sensitive information in prompts
- −Don't expect skill to replace human judgment
💡 Pro Tips
- ★Be specific about desired format and style
- ★Ask for multiple options to choose from
- ★Request explanations to understand reasoning
- ★Combine AI efficiency with human expertise
When to Use This▌
✓ Use When
Use when skill capabilities match your task, clear ROI on time saved, and you can validate outputs. Best for repetitive tasks, learning, and quality improvement.
✗ Avoid When
Avoid when task requires deep expertise you can't validate, involves sensitive decisions, or when learning process is more valuable than speed of completion.
Learning Path▌
- 1Familiarize yourself with skill capabilities and limitations
- 2Start with low-risk, non-critical tasks
- 3Progress to more complex and valuable use cases
- 4Build expertise through regular use and experimentation
Discussion
Product Hunt–style comments (not star reviews)- No comments yet — start the thread.
general reviewsRatings
4.5★★★★★49 reviews- ★★★★★Kaira Lopez· Dec 28, 2024
Useful defaults in nextjs-dynamic-routes-params — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.
- ★★★★★Layla Ghosh· Dec 24, 2024
I recommend nextjs-dynamic-routes-params for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.
- ★★★★★Ren Jackson· Dec 12, 2024
nextjs-dynamic-routes-params fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.
- ★★★★★Shikha Mishra· Dec 8, 2024
nextjs-dynamic-routes-params fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.
- ★★★★★Yusuf Chawla· Dec 8, 2024
Registry listing for nextjs-dynamic-routes-params matched our evaluation — installs cleanly and behaves as described in the markdown.
- ★★★★★Layla Bansal· Nov 27, 2024
Useful defaults in nextjs-dynamic-routes-params — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.
- ★★★★★Hiroshi Kapoor· Nov 19, 2024
Registry listing for nextjs-dynamic-routes-params matched our evaluation — installs cleanly and behaves as described in the markdown.
- ★★★★★Kofi Sethi· Nov 15, 2024
nextjs-dynamic-routes-params reduced setup friction for our internal harness; good balance of opinion and flexibility.
- ★★★★★Layla Gill· Oct 18, 2024
I recommend nextjs-dynamic-routes-params for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.
- ★★★★★Ishan Abbas· Oct 10, 2024
nextjs-dynamic-routes-params reduced setup friction for our internal harness; good balance of opinion and flexibility.
showing 1-10 of 49
1 / 5