Skip to content

Commit 78e59c9

Browse files
icyJosephhuozhi
authored andcommitted
docs: disclosure on path-to-regexp (#85629)
Prepping for a bit more helpful work with these matchers
1 parent d5253e3 commit 78e59c9

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

docs/01-app/03-api-reference/03-file-conventions/proxy.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ Configured matchers:
122122
2. Can include named parameters: `/about/:path` matches `/about/a` and `/about/b` but not `/about/a/c`
123123
3. Can have modifiers on named parameters (starting with `:`): `/about/:path*` matches `/about/a/b/c` because `*` is _zero or more_. `?` is _zero or one_ and `+` _one or more_
124124
4. Can use regular expression enclosed in parenthesis: `/about/(.*)` is the same as `/about/:path*`
125+
5. Are anchored to the start of the path: `/about` matches `/about` and `/about/team` but not `/blog/about`
125126

126127
Read more details on [path-to-regexp](https://github.com/pillarjs/path-to-regexp#path-to-regexp-1) documentation.
127128

docs/01-app/03-api-reference/05-config/01-next-config-js/headers.mdx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ module.exports = {
7575

7676
## Path Matching
7777

78-
Path matches are allowed, for example `/blog/:slug` will match `/blog/hello-world` (no nested paths):
78+
Path matches are allowed, for example `/blog/:slug` will match `/blog/first-post` (no nested paths):
7979

8080
```js filename="next.config.js"
8181
module.exports = {
@@ -99,6 +99,12 @@ module.exports = {
9999
}
100100
```
101101

102+
The pattern `/blog/:slug` matches `/blog/first-post` and `/blog/post-1` but not a nested path like `/blog/a/b`. Patterns are anchored to the start, `/blog/:slug` will not match `/archive/blog/first-post`.
103+
104+
You can use modifiers on parameters: `*` (zero or more), `+` (one or more), `?` (zero or one). For example, `/blog/:slug*` matches `/blog`, `/blog/a`, and `/blog/a/b/c`.
105+
106+
Read more details on [path-to-regexp](https://github.com/pillarjs/path-to-regexp) documentation.
107+
102108
### Wildcard Path Matching
103109

104110
To match a wildcard path you can use `*` after a parameter, for example `/blog/:slug*` will match `/blog/a/b/c/d/hello-world`:

docs/01-app/03-api-reference/05-config/01-next-config-js/redirects.mdx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ When `/old-blog/post-1?hello=world` is requested, the client will be redirected
5656

5757
## Path Matching
5858

59-
Path matches are allowed, for example `/old-blog/:slug` will match `/old-blog/hello-world` (no nested paths):
59+
Path matches are allowed, for example `/old-blog/:slug` will match `/old-blog/first-post` (no nested paths):
6060

6161
```js filename="next.config.js"
6262
module.exports = {
@@ -72,6 +72,12 @@ module.exports = {
7272
}
7373
```
7474

75+
The pattern `/old-blog/:slug` matches `/old-blog/first-post` and `/old-blog/post-1` but not `/old-blog/a/b` (no nested paths). Patterns are anchored to the start: `/old-blog/:slug` will not match `/archive/old-blog/first-post`.
76+
77+
You can use modifiers on parameters: `*` (zero or more), `+` (one or more), `?` (zero or one). For example, `/blog/:slug*` matches `/blog`, `/blog/a`, and `/blog/a/b/c`.
78+
79+
Read more details on [path-to-regexp](https://github.com/pillarjs/path-to-regexp) documentation.
80+
7581
### Wildcard Path Matching
7682

7783
To match a wildcard path you can use `*` after a parameter, for example `/blog/:slug*` will match `/blog/a/b/c/d/hello-world`:

docs/01-app/03-api-reference/05-config/01-next-config-js/rewrites.mdx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ module.exports = {
163163
164164
## Path Matching
165165

166-
Path matches are allowed, for example `/blog/:slug` will match `/blog/hello-world` (no nested paths):
166+
Path matches are allowed, for example `/blog/:slug` will match `/blog/first-post` (no nested paths):
167167

168168
```js filename="next.config.js"
169169
module.exports = {
@@ -178,6 +178,12 @@ module.exports = {
178178
}
179179
```
180180

181+
The pattern `/blog/:slug` matches `/blog/first-post` and `/blog/post-1` but not `/blog/a/b` (no nested paths). Patterns are anchored to the start: `/blog/:slug` will not match `/archive/blog/first-post`.
182+
183+
You can use modifiers on parameters: `*` (zero or more), `+` (one or more), `?` (zero or one). For example, `/blog/:slug*` matches `/blog`, `/blog/a`, and `/blog/a/b/c`.
184+
185+
Read more details on [path-to-regexp](https://github.com/pillarjs/path-to-regexp) documentation.
186+
181187
### Wildcard Path Matching
182188

183189
To match a wildcard path you can use `*` after a parameter, for example `/blog/:slug*` will match `/blog/a/b/c/d/hello-world`:

0 commit comments

Comments
 (0)