Dynamic Route Segment
~10 mins
- nextjs
Dynamic Route Segment
Next.js allows you to create Dynamic Route Segments when you don't know the exact segment name and want to create routes based on data. This could be blog post titles, product pages, etc. You can create dynamic route segments by wrapping a folder's name in square brackets. For example, [id], [post] or [slug].
- `/app/tasks/[id]/page.tsx
import { fetchInvoiceById, fetchCustomers } from '@/app/lib/data';
export default async function Page({ params }: { params: { id: string } }) {
const id = params.id;
const [task, user] = await Promise.all([fetchTaskById(id), fetchUser()]);
}