Docs update: Redirect paths with parentheses (#24062)
It took me quite a while to understand that in order to redirect from `/english(default)/:path` to `/en-us/:path`, I have to escape the parentheses in the source with double backslashes so I thought I'd suggest it as a small doc update. ## Documentation / Examples - [x] Make sure the linting passes
This commit is contained in:
parent
6e22a440e2
commit
646a881183
3 changed files with 52 additions and 1 deletions
|
@ -154,6 +154,23 @@ module.exports = {
|
|||
}
|
||||
```
|
||||
|
||||
The following characters `(`, `)`, `{`, `}`, `:`, `*`, `+`, `?` are used for regex path matching, so when used in the `source` as non-special values they must be escaped by adding `\\` before them:
|
||||
|
||||
```js
|
||||
module.exports = {
|
||||
async redirects() {
|
||||
return [
|
||||
{
|
||||
// this will match `/english(default)/something` being requested
|
||||
source: '/english\\(default\\)/:slug',
|
||||
destination: '/en-us/:slug',
|
||||
permanent: false,
|
||||
},
|
||||
]
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
## Header, Cookie, and Query Matching
|
||||
|
||||
Note: this feature is still experimental and not covered by semver and is to be used at your own risk until it is made stable.
|
||||
|
|
|
@ -82,7 +82,7 @@ module.exports = {
|
|||
|
||||
### Regex Path Matching
|
||||
|
||||
To match a regex path you can wrap the regex in parenthesis after a parameter, for example `/post/:slug(\\d{1,})` will match `/post/123` but not `/post/abc`:
|
||||
To match a regex path you can wrap the regex in parentheses after a parameter, for example `/post/:slug(\\d{1,})` will match `/post/123` but not `/post/abc`:
|
||||
|
||||
```js
|
||||
module.exports = {
|
||||
|
@ -98,6 +98,23 @@ module.exports = {
|
|||
}
|
||||
```
|
||||
|
||||
The following characters `(`, `)`, `{`, `}`, `:`, `*`, `+`, `?` are used for regex path matching, so when used in the `source` as non-special values they must be escaped by adding `\\` before them:
|
||||
|
||||
```js
|
||||
module.exports = {
|
||||
async redirects() {
|
||||
return [
|
||||
{
|
||||
// this will match `/english(default)/something` being requested
|
||||
source: '/english\\(default\\)/:slug',
|
||||
destination: '/en-us/:slug',
|
||||
permanent: false,
|
||||
},
|
||||
]
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
## Header, Cookie, and Query Matching
|
||||
|
||||
Note: this feature is still experimental and not covered by semver and is to be used at your own risk until it is made stable.
|
||||
|
|
|
@ -178,6 +178,23 @@ module.exports = {
|
|||
}
|
||||
```
|
||||
|
||||
The following characters `(`, `)`, `{`, `}`, `:`, `*`, `+`, `?` are used for regex path matching, so when used in the `source` as non-special values they must be escaped by adding `\\` before them:
|
||||
|
||||
```js
|
||||
module.exports = {
|
||||
async redirects() {
|
||||
return [
|
||||
{
|
||||
// this will match `/english(default)/something` being requested
|
||||
source: '/english\\(default\\)/:slug',
|
||||
destination: '/en-us/:slug',
|
||||
permanent: false,
|
||||
},
|
||||
]
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
## Header, Cookie, and Query Matching
|
||||
|
||||
Note: this feature is still experimental and not covered by semver and is to be used at your own risk until it is made stable.
|
||||
|
|
Loading…
Reference in a new issue