mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
This ensures we leverage the fetch cache when calling `generateStaticParams` and also ensures paths with `generateStaticParams` without `dynamicParams = false` don't error when only partial params are provided. x-ref: [slack thread](https://vercel.slack.com/archives/C035J346QQL/p1678149362238089)
33 lines
630 B
JavaScript
33 lines
630 B
JavaScript
export const dynamicParams = true
|
|
|
|
export async function generateStaticParams() {
|
|
const res = await fetch(
|
|
'https://next-data-api-endpoint.vercel.app/api/random?staticGen'
|
|
)
|
|
|
|
const data = await res.text()
|
|
const fetchSlug = Math.round(Number(data) * 100)
|
|
console.log('partial-gen-params fetch', fetchSlug)
|
|
|
|
return [
|
|
{
|
|
slug: 'first',
|
|
},
|
|
{
|
|
slug: 'second',
|
|
},
|
|
{
|
|
slug: fetchSlug + '',
|
|
},
|
|
]
|
|
}
|
|
|
|
export default function Page({ params }) {
|
|
return (
|
|
<>
|
|
<p id="page">/partial-gen-params/[lang]/[slug]</p>
|
|
<p id="params">{JSON.stringify(params)}</p>
|
|
</>
|
|
)
|
|
}
|