Capítulo 418 de 456

trailingSlash

Core Idea

Config option that controls whether Next.js URLs resolve with or without a trailing slash. Default behavior redirects /about/ to /about; enabling the option reverses that.

Key Concepts

  • trailingSlash: true: makes Next.js redirect /about to /about/ instead of the default opposite behavior.
  • Exceptions: static file URLs (with extensions) and paths under .well-known/ never get a trailing slash appended.
  • With output: "export": when trailingSlash: true is combined with static export, /about outputs as /about/index.html instead of /about.html.

Code Examples

module.exports = {
  trailingSlash: true,
}
  • O que demonstra: ativa trailing slash em todas as URLs, exceto arquivos estáticos e .well-known/.

Reference Tables

VersionChanges
v9.5.0trailingSlash added.

Key Takeaways

  1. Default: Next.js remove trailing slash via redirect; trailingSlash: true inverte esse comportamento.
  2. Arquivos estáticos (com extensão) e .well-known/ nunca ganham trailing slash, mesmo com a flag ligada.
  3. Combinar com output: "export" muda o nome do arquivo HTML gerado (index.html em subpasta em vez de .html).

Connects To

  • output: "export": interage diretamente com a nomeação dos arquivos HTML de export estático.