How do dynamic routes work, and what does generateStaticParams do?
Take a moment.
Say your answer out loud or write it down first — retrieval is what makes it stick. Reveal when you're ready.
Short answer
[param] folders match dynamic segments, [...slug] catches rest, [[slug]] is optional catch-all. generateStaticParams pre-renders known param values at build time (SSG); unknown params either render on demand or 404 depending on dynamicParams.
Detailed explanation
Dynamic segments make data-driven URLs type-safe-ish: app/blog/[slug]/page.tsx receives params.slug. Catch-all [...slug] matches /docs/a/b/c; optional catch-all [[...slug]] also matches the bare prefix. In Server Components params arrives as a prop (a Promise in recent versions). generateStaticParams returns the list of values to prerender at build — like getStaticPaths before it — commonly fetching all slugs from your CMS or DB: return posts.map(p => ({ slug: p.slug })). The companion flag dynamicParams controls strangers: true (default) renders unknown params on demand then caches; false hard-404s anything not prerendered. Combine with revalidate for ISR on dynamic pages. Nested dynamics compose — parent and child each declare their own params. Common production concern: thousands of params × long builds → prefer on-demand rendering with caching over exhaustive prerendering.
Example
// app/blog/[slug]/page.tsx
export async function generateStaticParams() {
const posts = await getAllPosts();
return posts.map((p) => ({ slug: p.slug }));
}
export const revalidate = 3600; // ISR refresh hourly
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={post} />;
}Interview tip
Name all three segment syntaxes quickly, then focus on the generateStaticParams + dynamicParams pairing — that's where understanding actually shows.
Common mistakes
- Mixing up [...slug] and [[...slug]] semantics.
- Not knowing dynamicParams controls whether unknown paths render.