未验证 提交 a11d9939 编写于 作者: J Joe Haddad 提交者: GitHub

Stabilize Trailing Slash API (#15331)

Closes #15330
上级 047b73b8
......@@ -4,18 +4,13 @@ description: Configure Next.js pages to resolve with or without a trailing slash
# Trailing Slash
> **Warning**: This feature is **experimental and may not work as expected**.
> You must enable the `trailingSlash` experimental option to try it.
By default Next.js will redirect urls with trailing slashes to their counterpart without a trailing slash. For example `/about/` will redirect to `/about`. You can configure this behavior to act the opposite way, where urls without trailing slashes are redirected to their counterparts with trailing slashes.
Open `next.config.js` and add the `trailingSlash` config:
```js
module.exports = {
experimental: {
trailingSlash: true,
},
trailingSlash: true,
}
```
......
......@@ -839,7 +839,7 @@ export default async function getBaseWebpackConfig(
}
: {}),
'process.env.__NEXT_TRAILING_SLASH': JSON.stringify(
config.experimental.trailingSlash
config.trailingSlash
),
'process.env.__NEXT_EXPORT_TRAILING_SLASH': JSON.stringify(
config.exportTrailingSlash
......
......@@ -357,7 +357,7 @@ export default async function loadCustomRoutes(
loadRedirects(config),
])
if (config.experimental.trailingSlash) {
if (config.trailingSlash) {
redirects.unshift(
{
source: '/:path*/:file.:ext/',
......
......@@ -37,8 +37,8 @@ const defaultConfig: { [key: string]: any } = {
basePath: '',
exportTrailingSlash: false,
sassOptions: {},
trailingSlash: false,
experimental: {
trailingSlash: false,
cpus: Math.max(
1,
(Number(process.env.CIRCLE_NODE_TOTAL) ||
......
module.exports = {
experimental: {
// <placeholder>
},
// trailingSlash: boolean,
// basePath: '/docs',
}
......@@ -178,7 +178,7 @@ function testWithTrailingSlash() {
describe('Trailing slashes', () => {
describe('dev mode, trailingSlash: false', () => {
beforeAll(async () => {
nextConfig.replace('// <placeholder>', 'trailingSlash: false')
nextConfig.replace('// trailingSlash: boolean', 'trailingSlash: false')
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
......@@ -192,7 +192,7 @@ describe('Trailing slashes', () => {
describe('dev mode, trailingSlash: true', () => {
beforeAll(async () => {
nextConfig.replace('// <placeholder>', 'trailingSlash: true')
nextConfig.replace('// trailingSlash: boolean', 'trailingSlash: true')
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
......@@ -206,7 +206,7 @@ describe('Trailing slashes', () => {
describe('production mode, trailingSlash: false', () => {
beforeAll(async () => {
nextConfig.replace('// <placeholder>', 'trailingSlash: false')
nextConfig.replace('// trailingSlash: boolean', 'trailingSlash: false')
await nextBuild(appDir)
appPort = await findPort()
app = await nextStart(appDir, appPort)
......@@ -238,7 +238,7 @@ describe('Trailing slashes', () => {
describe('production mode, trailingSlash: true', () => {
beforeAll(async () => {
nextConfig.replace('// <placeholder>', 'trailingSlash: true')
nextConfig.replace('// trailingSlash: boolean', 'trailingSlash: true')
await nextBuild(appDir)
appPort = await findPort()
app = await nextStart(appDir, appPort)
......@@ -275,7 +275,7 @@ describe('Trailing slashes', () => {
describe('dev mode, with basepath, trailingSlash: true', () => {
beforeAll(async () => {
nextConfig.replace('// <placeholder>', 'trailingSlash: true')
nextConfig.replace('// trailingSlash: boolean', 'trailingSlash: true')
nextConfig.replace('// basePath:', 'basePath:')
appPort = await findPort()
app = await launchApp(appDir, appPort)
......@@ -300,7 +300,7 @@ describe('Trailing slashes', () => {
describe('production mode, with basepath, trailingSlash: true', () => {
beforeAll(async () => {
nextConfig.replace('// <placeholder>', 'trailingSlash: true')
nextConfig.replace('// trailingSlash: boolean', 'trailingSlash: true')
nextConfig.replace('// basePath:', 'basePath:')
await nextBuild(appDir)
appPort = await findPort()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册