NextJS 不会在静态导出中为子文件夹创建 index.html

San*_*ndy 9 amazon-s3 next.js

我使用 NextJS 创建了一个完全静态的网站,export对其进行了编辑,然后使用静态网站托管将其托管在 S3 上。我可以单击周围并成功查看所有页面,包括example.com/blog. 但是,如果在浏览器中单击刷新,或example.com/blog直接输入,则会收到 404 Not Found 错误。

查看导出的文件时,我看到 /blog/ 没有 index.html 文件,尽管应该有(在我看来),因为在原始源文件中我有一个/blog/index.ts文件,并且在开发模式下我可以刷新localhost/blog或输入它直接并且按预期工作。

总之,我相信 NextJS 应该创建一个/blog/index.html文件,但它没有。有什么办法可以强制这样做吗?难道我做错了什么?谢谢你!

Mar*_*k G 12

index.html要在导出到静态 HTML 时生成文件,请启用trailingSlash以下设置next.config.js

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

./out/blog.html现在应该成为./out/blog/index.html导出后。