Module F-5·22 min read

Slug segments, catch-all routes, async params in Next.js 15, generateStaticParams, and the full suite of client-side navigation hooks including the new useLinkStatus.

JJS
Written by Jatin Jain Saraf · Senior Software Engineer

F-5 — Dynamic Routes, Params, and Navigation Hooks

Who this is for: Developers who understand Server Components and basic data fetching from F-3 and F-4, and now need to work with URL parameters, statically pre-render dynamic content, and navigate programmatically from Client Components. This module covers the full routing toolkit — including the navigation hooks that Next.js 15 and 16 extended significantly.


Dynamic Segments: The Mechanics

A folder with square brackets creates a dynamic segment. Every page inside that folder receives the matched value as a params prop:

text

The folder name — without brackets — becomes the key in params:

tsx

In Next.js 15+, params is a Promise. Always await it. If you're reading legacy code from Next.js 14, you'll see synchronous destructuring — that still works during the Next.js 15 transition period, but new code should await params.


Nested Dynamic Segments

You can nest dynamic segments. Each folder adds a key to params:

text
tsx

Deeply nested dynamic routes are common in content-heavy applications. Keep in mind that each level of nesting is a separate layout boundary — you can have app/users/[userId]/layout.tsx that fetches the user profile once and shares it across all pages under that user's namespace.


Catch-All and Optional Catch-All Segments

Catch-all [...slug] matches one or more path segments and returns them as an array:

text
tsx

Note: catch-all does not match the root path /docs — only paths with at least one additional segment.

Optional catch-all [[...slug]] also matches the root:

text

Optional catch-all is the pattern for CMS-driven sites where the homepage is content-managed alongside all other pages. The root check is if (!slug).


generateStaticParams — Pre-rendering Dynamic Routes

By default, dynamic routes render on-demand at request time (server-rendered). generateStaticParams tells Next.js to pre-render specific parameter values at build time, generating static HTML files for those paths.

tsx

At build time, Next.js calls generateStaticParams(), gets the list of IDs, and pre-renders each one. The resulting HTML files are stored and served directly from the CDN for those paths — no server work per request.

What happens to paths not in generateStaticParams? By default, they render on-demand (dynamic rendering). You can change this behaviour:

tsx

dynamicParams = false is the strict mode. Use it when your entire dataset is known at build time (a fixed set of blog posts, documentation pages) and you want 404s for any URL that isn't in your dataset.

For catch-all routes:

tsx

Each array entry maps to one path. ['api', 'authentication'] pre-renders /docs/api/authentication.


searchParams — The Query String

Sign in to keep reading

The rest of this module is free — sign in with Google to unlock it and track your progress.

Sign in & Register

Discussion

0

Join the discussion

Loading comments...

© 2026 Jatin Jain Saraf (JJS). All rights reserved.