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 }))
}

Explanation

Alternatively, the child can return both params at once. Top-down generation keeps each level's data fetching small.

Further reading

Problem with a question

Next.js · Senior · question 68

Test yourself

Take the Next.js · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz