trailingSlash

預設情況下,Next.js 會將帶有結尾斜線的網址重新導向至不帶斜線的對應網址。例如 /about/ 會重新導向至 /about。您可以設定此行為以相反方式運作,讓不帶結尾斜線的網址重新導向至帶有斜線的對應網址。

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

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

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

版本歷史

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

On this page