Question presented to candidate: "We have thousands of blog posts and a product catalogue with nested categories. How do you model those URLs in the App Router, and what exactly does the page receive?"
What a strong answer should cover:
- A folder named
[slug]is a dynamic segment: it matches one URL segment and passes it asparams.slug(a string). [...slug]is a catch-all: one or more segments, as a string array; the bare parent URL does not match.[[...slug]]is an optional catch-all: zero or more segments, so the parent URL also matches and the value isundefined.paramsis a Promise since Next.js 15:await paramsin Server Components,use(params)oruseParams()in Client Components; type it withPageProps<'/route'>.generateStaticParamsprerenders known values at build time;dynamicParams = falseturns unknown values into a 404.- Values arrive URL-encoded and unvalidated: decode and validate them, and call
notFound()when nothing matches.
Clarifying questions expected:
- "Are the slugs known at build time?" β decides between prerendering with
generateStaticParamsand rendering on demand. - "Should an unknown slug 404 or be generated on first request?" β that is the
dynamicParamsswitch.
Code / implementation expected: Yes β [slug], [...categories] and [[...path]] pages reading params.