new·Earn with mozg — 20% of every monthSend somebody here and take a fifth of every plan payment they make, for as long as they keep paying — not a bounty on the first invoice. Your handle is the link, the window is thirty days, and the commission lands on your balance the second they pay. Free to join: if you have signed in, you already have the link. mozg.sh/earnall news →
mozg.beta
Sign in

Next.js App Router · all subjects

dynamic routes and segments

5 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

generateStaticParams must return at least one param

With Cache Components, `generateStaticParams` must return at least one param. Returning an empty array now errors with `empty-generate-static-params`. Next.js needs at least one param to prerender the route and validate it produces a non-empty static shell.

Paths not returned by generateStaticParams are rendered on request

Paths not returned by `generateStaticParams` are still served. Next.js prerenders a static shell for the unknown params and streams the rest at request time.

dynamicParams not supported with Cache Components

With Cache Components enabled, exporting `dynamicParams` fails the build. Params not returned by `generateStaticParams` are rendered on request. If you used `dynamicParams: false` to reject unknown params, call `notFound()` in the page when the param doesn't resolve to real data.

Await params inside Suspense for static shell

To produce a static shell with dynamic params, pass the `params` promise into a `<Suspense>` boundary instead of awaiting it at the top of the component, so unknown params can still prerender.

Client hooks reading dynamic params need Suspense

Client hooks that read the route (`usePathname`, `useParams`, `useSelectedLayoutSegment`, `useSelectedLayoutSegments`) suspend when the route's pathname depends on dynamic params not yet known. Wrap the component that reads the hook in `<Suspense>`, pushing the read down to the smallest leaf so the rest stays prerendered. `useSearchParams` always needs a `<Suspense>` boundary.

Give your agent this brain