9

I would like to host my React Project on Amazon S3.

I am developing it with Next.js.

the folder tree is like below this.

pages
 |- auth
 |    |- index.tsx
 |- (...)
 |- index.tsx

and I did

next build && next export

After building and exporting, I expected it

out
 |- _next
 |- auth
 |    |- index.html /* I want another index.html */
 |- (...)
 |- index.html
 |- static

but I got it,

 |- _next
 |- auth.html /*I need /auth/index.html*/
 |- (...)
 |- index.html
 |- static

How could I achieve it.

Thank you in advance.

2 Answers 2

20

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

Just add exportTrailingSlash: true to next.config.js.

module.exports = {
  trailingSlash: true,
}
3
  • 3
    Note: the exportTrailingSlash option has been renamed to trailingSlash. Commented May 9, 2021 at 11:45
  • 1
    trailingSlash: true, did what I wanted, it created the folder structure where /about becomes /about/index.html -- I just didn't believe it
    – thedanotto
    Commented Mar 19, 2022 at 5:29
  • 4
    How can a webserver like nginx do anything without any .html exported ? What is this NextJS black magic ? Commented Apr 8, 2022 at 20:48
5

next.config.js

module.exports = {
  exportPathMap: async function (defaultPathMap) {
    return {
      '/auth/index.html': { page: '/auth' },
    };
  }
}

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