nextjs-pathname-id-fetch_skill

This skill explains and implements the Next.js pathname ID fetch pattern to load data from URL parameters in server components.

69

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill wsimmonds/claude-nextjs-skills --skill nextjs-pathname-id-fetch

  • SKILL.md6.8 KB

Overview

This skill documents a focused Next.js pattern for fetching data based on URL parameters. It explains creating dynamic route folders like [id] or [slug], accessing route params in server components, and using that identifier to fetch and render item details. The guidance targets common detail pages such as products, posts, and profiles.

How this skill works

Create a dynamic route folder (for example app/[id]/page.tsx), implement a server component, await the params object (Next.js 15+), extract the identifier, and call your API using that value. Return rendered JSX with the fetched data and handle missing or error responses appropriately. Keep the component server-side—do not add 'use client'.

When to use it

  • Building product, blog post, or user profile detail pages that rely on a URL identifier
  • Admin or dashboard pages that drill into a single resource via an ID in the path
  • Simple routing cases where a single dynamic segment (e.g., [id] or [slug]) provides the required context
  • When you need server-side data fetching tied directly to the current pathname
  • When you want a minimal, predictable routing structure without catch-all complexity

Best practices

  • Name dynamic folders with brackets: app/[id]/page.tsx (no brackets = static route)
  • Keep the page a server component and await params for Next.js 15+: const { id } = await params
  • Type params precisely (e.g., Promise<{ id: string }>) and avoid using any
  • Use fetch with cache control (e.g., { cache: 'no-store' }) when up-to-date data is required
  • Handle fetch failures and render clear loading/error states in the UI

Example use cases

  • Product detail page at /products/123 implemented as app/[id]/page.tsx fetching /api/products/123
  • Blog post page at /blog/my-slug implemented as app/[slug]/page.tsx fetching the post by slug
  • Admin order view at /admin/orders/ord-456 implemented as app/[orderId]/page.tsx loading order details
  • Simple docs lookup where a doc id in the path maps to a single API call and render
  • User profile page at /users/alice implemented using a dynamic [username] folder and server fetch

FAQ

No. Keep this as a server component. Adding 'use client' removes server-side access to params and can break the pattern.

How should I type params for Next.js 15+?

Type params as a Promise of an object, e.g., { params }: { params: Promise<{ id: string }> } and await params before reading the id.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational