Dynamic Routing Patterns
When to use this skill
- •Creating pages that depend on a parameter (slug, ID).
- •Handling
paramsin Next.js 15 Server Components.
Workflow (Next.js 15)
- • Define the folder:
app/tours/[id]/page.tsx. - • Access
paramsas a Promise (required in v15). - • Fetch data based on the resolved
id.
Implementation
typescript
interface TourPageProps {
params: Promise<{ id: string }>;
}
export default async function TourDetailsPage({ params }: TourPageProps) {
const { id } = await params; // Await the promise
const tour = await TourService.getById(id);
return (
<main>
<h1>{tour.title}</h1>
{/* ... */}
</main>
);
}
Instructions
- •Metadata: Await
paramsingenerateMetadataas well. - •Loading: Use
loading.tsxin the directory for automatic fallback UI.