6

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.

JP McGlone
  • 91
  • 1
  • 6
  • 1
    Does this answer your question? [How to deal with NextJS exporting files with .html extension but in there is no .html](https://stackoverflow.com/questions/62867105/how-to-deal-with-nextjs-exporting-files-with-html-extension-but-inlink-there) – Carsten Führmann Mar 10 '21 at 22:00

2 Answers2

3

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

JP McGlone
  • 91
  • 1
  • 6
  • 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. – Carsten Führmann Mar 10 '21 at 21:43
3
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

JiN
  • 31
  • 5