Next.js · Senior · Question 68 of 75
How does generateStaticParams work for nested dynamic segments like /[category]/[product]?
// app/[category]/[product]/page.tsx
export async function generateStaticParams({ params }) {
const { category } = params
return (await getProducts(category)).map((p) => ({ product: p.slug }))
}- ✓Correct answer: The parent's function runs first, and the child's function is called once per parent result with those
params - 2Only the deepest segment may export
generateStaticParams - 3All combinations are generated automatically
Explanation
Alternatively, the child can return both params at once. Top-down generation keeps each level's data fetching small.