Generate params from the bottom up
export async function generateStaticParams() {
const products = await fetch('https://.../products').then((res) => res.json())
return products.map((product) => ({
category: product.category.slug,
product: product.id,
}))
}
export default function Page({
params,
}: {
params: { category: string; product: string }
}) {
// ...
}
Dynamic segments starting from the child route segment and moving towards the parent route segment.
For example, in the route app/products/[category]/[product]/page.tsx, we want to generate params for both [category] and [product]. To achieve this, we utilize the generateStaticParams function.
This function asynchronously fetches product data from an API and maps each product to an object containing category and product properties. These properties represent dynamic segments that will populate the route.
Inside the Page component, we receive category and product as parameters from the params object, enabling us to use them for rendering content related to specific product categories and products.
Next.js Functions: generateStaticParams
“generateStaticParams” is a function name or identifier used as a placeholder in the context of NextJS development. It doesn’t represent a built-in or standard function in NextJS itself. Instead, it seems to be a hypothetical function name that could be used to illustrate the process of generating static parameters in a NextJS application.