Capítulo 248 de 456

trailingSlash

Core Idea

Controls whether Next.js URLs resolve with or without a trailing slash, and which direction the automatic redirect goes.

Key Concepts

  • trailingSlash: boolean config; default false redirects /about//about. Setting true reverses it, redirecting /about/about/.
  • Exceptions with trailingSlash: true: static file URLs (files with extensions) and any path under .well-known/ never get a trailing slash appended.
  • Interaction with output: "export": with trailingSlash: true, /about outputs /about/index.html instead of the default /about.html.

Code Examples

module.exports = {
  trailingSlash: true,
}
  • O que demonstra: inverte o comportamento padrão para exigir barra final nas URLs.

Reference Tables

VersionChanges
v9.5.0trailingSlash added.

Key Takeaways

  1. Default do Next.js é remover a barra final via redirect automático.
  2. Arquivos estáticos (com extensão) e .well-known/ nunca recebem barra final, mesmo com a opção ligada.
  3. Combinado com output: "export", muda o nome do arquivo HTML gerado por rota.

Connects To

  • output: "export" (static exports): trailingSlash altera o nome do arquivo de saída gerado.