Next.js Developer interview question · Most asked
How do dynamic routes, catch-all and optional catch-all segments work?
Summary
[slug] matches one segment, [...slug] matches one or more segments (array), and [[...slug]] also matches the parent path with no segments. Params arrive in the page's params prop.
Longer Answer
In Next.js 15+, params and searchParams are Promises in Server Components, so you await params. Use generateStaticParams to pre-render known params at build time.
Code Example
// app/blog/[slug]/page.tsx
export default async function Post({ params }: { params: Promise<{ slug: string }> }) {
const { slug } = await params;
const post = await getPost(slug);
if (!post) notFound();
return <article>{post.title}</article>;
}
export async function generateStaticParams() {
const posts = await getAllPosts();
return posts.map((p) => ({ slug: p.slug }));
}
Key Points
[id]single segment[...parts]one or more[[...parts]]zero or moreparamsis a Promise in Next 15+
More most-asked Next.js Developer questions
- How does data fetching work in the App Router?
- How did caching defaults change in Next.js 15?
- What happens, step by step, when a request reaches a Next.js App Router application?
- What is Next.js and what problems does it solve on top of React?
- What are the differences between the App Router and the Pages Router?
- What is the difference between Server Components and Client Components?
- Explain the App Router file conventions: page, layout, loading, error, not-found, template and route.
- Explain SSR, SSG, ISR and CSR in Next.js.