8

I'm building a static site using next.js, and I want my website.com/about.html to work just as: website.com/about -- I'm not sure why it's forcing me to type .html.

Even if I structure my project: pages/about/index.js -- it generates a about.html instead of about/index.html on the static site.

1

2 Answers 2

4

I found the answer on next's website:

module.exports = {
  exportTrailingSlash: true,
}

https://nextjs.org/docs/api-reference/next.config.js/exportPathMap#adding-a-trailing-slash

1
  • This works, but there is an issue: When the user types no trailing slash, there is a redirect to the URL with the slash. That redirect costs time, in particular in high-latency scenarios. Commented Mar 10, 2021 at 21:43
4
module.exports = {
  trailingSlash: true,
}

You can use it if you have NEXT.JS 9.5 or higher versions.

Take a look at this NEXT.JS official document. https://nextjs.org/docs/api-reference/next.config.js/trailing-slash

Not the answer you're looking for? Browse other questions tagged or ask your own question.