You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds the variadic section to the path-params guide and routing
concepts, includes optional and variadic parameters in the route
matching order (optional parameters were missing from it), and maps
Next.js optional catch-all segments to variadic parameters in the
migration guide.
Copy file name to clipboardExpand all lines: docs/router/guide/path-params.md
+91Lines changed: 91 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -721,6 +721,97 @@ function PostsComponent() {
721
721
722
722
<!-- ::end:framework -->
723
723
724
+
## Variadic Path Parameters
725
+
726
+
A regular path param matches exactly one segment. A variadic path parameter, written `{...$paramName}`, matches **zero or more** segments and provides them back to you as an array. The path can keep going after it, so it also works between fixed parts of the URL:
727
+
728
+
-`files/{...$path}/preview`
729
+
-`$bucket/{...$folders}/$file`
730
+
731
+
Let's build a route for files that can be nested in arbitrarily deep folders:
This one route matches `/media/kyoto.jpg`, `/media/photos/kyoto.jpg` and `/media/photos/2026/kyoto.jpg`, binding `folders` to `[]`, `['photos']` and `['photos', '2026']` respectively. The array is never `undefined` since a variadic that matched nothing gives you an empty array. Matching is non-greedy, so the variadic consumes as few segments as the rest of the path allows, and static, required or optional segments in the same position always win over it. Each matched segment is percent-decoded on its own, so an encoded `/` inside a folder name stays inside that folder's value.
780
+
781
+
When navigating, pass an array for the variadic param. An empty (or omitted) array drops the segment entirely:
A route path can contain up to three variadic segments, as long as consecutive ones are separated by at least one static segment; they resolve left to right, each consuming as little as possible. Prefixes and suffixes are not supported on variadic segments, and a variadic must be separated from a splat by at least one static segment.
812
+
813
+
> 🧠 Use a variadic parameter when segments _between_ two known parts of the URL vary in depth. If you just want to capture "the rest of the URL" with no routes after it, a [splat route](../routing/routing-concepts.md#splat--catch-all-routes) (`$`) is simpler.
814
+
724
815
## Internationalization (i18n) with Optional Path Parameters
725
816
726
817
Optional path parameters are excellent for implementing internationalization (i18n) routing patterns. You can use prefix patterns to handle multiple languages while maintaining clean, SEO-friendly URLs.
Copy file name to clipboardExpand all lines: docs/router/routing/routing-concepts.md
+52Lines changed: 52 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -325,6 +325,58 @@ This route matches `/posts`, `/posts/tech`, and `/posts/tech/hello-world`.
325
325
326
326
> 🧠 Routes with optional parameters are ranked lower in priority than exact matches, ensuring that more specific routes like `/posts/featured` are matched before `/posts/{-$category}`.
327
327
328
+
## Variadic Path Parameters
329
+
330
+
Variadic path parameters match **zero or more** URL segments in the middle of a path and bind them as an `Array<string>`. They use the `{...$paramName}` syntax.
A variadic segment consumes as few segments as the rest of the pattern allows, and each matched segment is percent-decoded independently. A route path may contain up to three variadic segments as long as consecutive ones are separated by at least one static segment. Prefixes and suffixes are not supported on variadic segments. See [Path Params](../guide/path-params.md#variadic-path-parameters) for details.
377
+
378
+
> 🧠 Variadic parameter routes are ranked below dynamic and optional parameter routes and above splat routes: `/docs/$section/end` and `/docs/{-$section}/end` both win over `/docs/{...$rest}/end` for `/docs/guide/end`.
379
+
328
380
## Layout Routes
329
381
330
382
Layout routes are used to wrap child routes with additional components and logic. They are useful for:
0 commit comments