trailingSlash

預設情況下,Next.js 會將帶有尾部斜線的網址重新導向至不帶斜線的版本。例如 /about/ 會重新導向至 /about。您可以設定此行為使其反向運作,將不帶尾部斜線的網址重新導向至帶斜線的版本。

開啟 next.config.js 並新增 trailingSlash 設定:

next.config.js
module.exports = {
  trailingSlash: true,
}

設定此選項後,像 /about 這樣的網址將會重新導向至 /about/

當與 output: "export" 設定一起使用時,/about 頁面將會輸出 /about/index.html (而非預設的 /about.html)。

版本歷史

版本變更內容
v9.5.0新增 trailingSlash 功能。

On this page