Lesson 1.3

Dynamic segments and route parameters

Wrapping a folder name in square brackets makes that segment dynamic, and its value arrives as a route parameter on the page and layout below it.

5mIntermediate16.9k students

Overview

Turning part of the URL into data

Wrapping a folder name in square brackets makes that segment dynamic, and its value arrives as a route parameter on the page and layout below it. A catch-all segment collects the rest of the path into an array instead of a single value.

For content you already know about at build time, generateStaticParams returns the list of parameter values to pre-render. Anything not in that list is still served — rendered on demand the first time it is requested — unless you explicitly opt out.

A dynamic route will eventually be handed a value that matches nothing. Calling notFound() from the page renders the nearest not-found boundary and returns a real 404 status, which matters for crawlers as much as for users.

In this lesson you will:

  • Capture a slug or id from the URL
  • Pre-render known paths with generateStaticParams
  • Handle a missing record with notFound

Resources

Previous Lesson
Next Lesson
Dynamic segments and route parameters — Next.js for Production — Vertex