Skip to content

Commit 5071fca

Browse files
authored
docs: clarify generateStaticParams and dynamicParams (#60083)
1 parent a5d87eb commit 5071fca

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

docs/02-app/02-api-reference/04-functions/generate-static-params.mdx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,24 @@ export default function Page({ params }) {
301301

302302
> **Good to know**: `fetch` requests are automatically [memoized](/docs/app/building-your-application/caching#request-memoization) for the same data across all `generate`-prefixed functions, Layouts, Pages, and Server Components. React [`cache` can be used](/docs/app/building-your-application/caching#request-memoization) if `fetch` is unavailable.
303303
304+
### Generate only a subset of params
305+
306+
You can generate a subset of params for a route by returning an array of objects with only the dynamic segments you want to generate. Then, by using the [`dynamicParams`](/docs/app/api-reference/file-conventions/route-segment-config#dynamicparams) segment config option, you can control what happens when a dynamic segment is visited that was not generated with `generateStaticParams`.
307+
308+
```jsx filename="app/blog/[slug]/page.js"
309+
// All posts besides the top 10 will be a 404
310+
export const dynamicParams = false
311+
312+
export async function generateStaticParams() {
313+
const posts = await fetch('https://.../posts').then((res) => res.json())
314+
const topPosts = posts.slice(0, 10)
315+
316+
return topPosts.map((post) => ({
317+
slug: post.slug,
318+
}))
319+
}
320+
```
321+
304322
## Version History
305323

306324
| Version | Changes |

0 commit comments

Comments
 (0)