generateStaticParams
The generateStaticParams function allows for the static generation of routes during the build process, when used alongside dynamic route segments, rather than dynamically generating them upon request.”
export async function generateStaticParams() {
const posts = await fetch('https://.../posts').then((res) => res.json())
return posts.map((post) => ({
slug: post.slug,
}))
}
// using the `params` returned by `generateStaticParams`
export default function Page({ params }) {
const { slug } = params
// ...
}
Parameters
- When multiple dynamic segments in a route utilize generateStaticParams, the child generateStaticParams function is triggered for each set of parameters generated by the parent.
- The params object holds the populated parameters from the parent generateStaticParams, enabling their utilization for generating parameters within a child segment.
Return Type
- generateStaticParams needs to give back a list of items. Each item in the list should represent a dynamic part of the route that’s been filled with data.
- In each item, there should be a part that represents the name of the dynamic segment, and another part that holds the actual value to fill in for that segment.
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.