Update docs for basePath custom-routes interop (#15140)
Follow-up to https://github.com/vercel/next.js/pull/15041 this updates the documentation for custom-routes to mention `basePath` handling with them
This commit is contained in:
parent
583d1a0a02
commit
3a9cb2c5b3
3 changed files with 86 additions and 0 deletions
|
@ -89,3 +89,37 @@ module.exports = {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Headers with basePath support
|
||||||
|
|
||||||
|
When leveraging [`basePath` support](/docs/api-reference/next.config.js/basepath.md) with headers each `source` is automatically prefixed with the `basePath` unless you add `basePath: false` to the header:
|
||||||
|
|
||||||
|
```js
|
||||||
|
module.exports = {
|
||||||
|
basePath: '/docs',
|
||||||
|
|
||||||
|
async headers() {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
source: '/with-basePath', // becomes /docs/with-basePath
|
||||||
|
headers: [
|
||||||
|
{
|
||||||
|
key: 'x-hello',
|
||||||
|
value: 'world'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
source: '/without-basePath', // is not modified since basePath: false is set
|
||||||
|
headers: [
|
||||||
|
{
|
||||||
|
key: 'x-hello',
|
||||||
|
value: 'world'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
basePath: false
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
|
@ -65,3 +65,30 @@ module.exports = {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Redirects with basePath support
|
||||||
|
|
||||||
|
When leveraging [`basePath` support](/docs/api-reference/next.config.js/basepath.md) with redirects each `source` and `destination` is automatically prefixed with the `basePath` unless you add `basePath: false` to the redirect:
|
||||||
|
|
||||||
|
```js
|
||||||
|
module.exports = {
|
||||||
|
basePath: '/docs',
|
||||||
|
|
||||||
|
async redirects() {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
source: '/with-basePath', // automatically becomes /docs/with-basePath
|
||||||
|
destination: '/another', // automatically becomes /docs/another
|
||||||
|
permanent: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// does not add /docs since basePath: false is set
|
||||||
|
source: '/without-basePath',
|
||||||
|
destination: '/another',
|
||||||
|
basePath: false,
|
||||||
|
permanent: false,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
|
@ -110,3 +110,28 @@ module.exports = {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Rewrites with basePath support
|
||||||
|
|
||||||
|
When leveraging [`basePath` support](/docs/api-reference/next.config.js/basepath.md) with rewrites each `source` and `destination` is automatically prefixed with the `basePath` unless you add `basePath: false` to the rewrite:
|
||||||
|
|
||||||
|
```js
|
||||||
|
module.exports = {
|
||||||
|
basePath: '/docs',
|
||||||
|
|
||||||
|
async rewrites() {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
source: '/with-basePath', // automatically becomes /docs/with-basePath
|
||||||
|
destination: '/another', // automatically becomes /docs/another
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// does not add /docs since basePath: false is set
|
||||||
|
source: '/without-basePath',
|
||||||
|
destination: '/another',
|
||||||
|
basePath: false,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
Loading…
Reference in a new issue