Static parameter generation
What you need to know
generateStaticParams is an App Router export that lists parameter objects for dynamic segments that should be prepared ahead of requests. A folder named [slug] identifies a variable path segment, but does not force request-time rendering. For a small article collection, supply the known public slugs and build pages from them.
By the end, you can: return known route parameter objects; predict generated paths.
app/articles/[slug]/page.tsx (complete small page)
import { notFound } from "next/navigation";const articles = new Map([["moss", "Moss care"], ["fern", "Fern care"]]);export function generateStaticParams() { return Array.from(articles.keys(), slug => ({ slug }));}export default async function Article({ params }: { params: Promise<{ slug: string }> }) { const title = articles.get((await params).slug); if (!title) notFound(); return <h1>{title}</h1>;}Expected behavior (not framework-tested): With an eligible static route, /articles/moss and /articles/fern are generated at build time. The parameter object uses the segment name, not a complete URL.
How it works
The generator runs before the associated pages are built; the page receives its own params promise and must resolve it. Return an array of objects whose keys match the dynamic segments. For a route containing [category]/[slug], a leaf generator can supply both keys. A parent layout can only generate parameters for its segment and ancestors. Use actual published records, a finite build set and stable unique identifiers. The generator is not rerun by ordinary ISR revalidation; changing an external inventory therefore requires an explicit strategy for new routes.
Two nested segments (partial leaf generator)
export function generateStaticParams() { return [ { category: "plants", slug: "moss" }, { category: "plants", slug: "fern" }, { category: "ocean", slug: "tide" } ];}Expected behavior (not framework-tested): For app/articles/[category]/[slug]/page.tsx, these objects identify three routes. They do not generate the Cartesian product of categories and slugs.
Common mistake
Do not return ["moss", "fern"] or [{ path: "/articles/moss" }] for [slug]. The shape must correspond to the segment. Never generate private records or rely on omitting a slug from the list as the only authorization measure.
Practice and verification
Write the parameter array for /articles/plants/moss and /articles/ocean/tide. Add a duplicate and explain why it should be removed before the build. Predict which paths are prepared, and separately decide the behavior for unknown paths.
Scope: App Router, proposed Next.js 16.x, Cache Components disabled for these labs. Snippets assume a reviewed TypeScript app and are static examples; framework behavior has not been executed. Exact supported patch and dependency set must be verified before running.
Further reading: Static Params · Dynamic Routes · Segment Config