Skip to main content

trailingSlash

默认情况下,Next.js 会将带有尾部斜杠的 URL 重定向到不带尾部斜杠的对应 URL。例如 /about/ 将重定向到 /about。你可以将此行为配置为以相反的方式执行操作,即不带尾部斜杠的 URL 将重定向到带尾部斜杠的对应 URL。

¥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.

打开 next.config.js 并添加 trailingSlash 配置:

¥Open next.config.js and add the trailingSlash config:

module.exports = {
trailingSlash: true,
}

设置此选项后,像 /about 这样的 url 将重定向到 /about/

¥With this option set, urls like /about will redirect to /about/.

当与 output: "export" 配置一起使用时,/about 页面将输出 /about/index.html(而不是默认的 /about.html)。

¥When used with output: "export" configuration, the /about page will output /about/index.html (instead of the default /about.html).

版本历史

¥Version History

版本变化
v9.5.0添加了 trailingSlash