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