Next.js - 导出index.html

zyn*_*nkn 9 next.js

我想在Amazon S3上托管我的 React 项目。

我正在开发它Next.js

文件夹树如下所示。

pages
 |- auth
 |    |- index.tsx
 |- (...)
 |- index.tsx
Run Code Online (Sandbox Code Playgroud)

我做到了

next build && next export
Run Code Online (Sandbox Code Playgroud)

构建和导出后,我期望它

out
 |- _next
 |- auth
 |    |- index.html /* I want another index.html */
 |- (...)
 |- index.html
 |- static
Run Code Online (Sandbox Code Playgroud)

但我明白了,

 |- _next
 |- auth.html /*I need /auth/index.html*/
 |- (...)
 |- index.html
 |- static
Run Code Online (Sandbox Code Playgroud)

我怎样才能实现呢。

先感谢您。

mov*_*vef 20

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

只需添加exportTrailingSlash: truenext.config.js.

module.exports = {
  trailingSlash: true,
}
Run Code Online (Sandbox Code Playgroud)

  • 像 nginx 这样的网络服务器如何在没有导出任何“.html”的情况下执行任何操作?NextJS 的黑魔法是什么? (4认同)
  • 注意:“exportTrailingSlash”选项已重命名为“trailingSlash”。 (3认同)

zyn*_*nkn 5

next.config.js

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