重新加载页面时,未加载下一个js中的静态导出

时间:2020-03-22 09:49:04

标签: reactjs next.js

我正在使用下一个js框架,我想使用静态导出,但是这里存在问题。

例如,我的网址为www.sitename.com/about

当我第一次去那里时,它起作用了,但是当我重新加载页面时,我得到了404页。

如果有帮助,我可以使用这样的路线:

<Link href="/about">
    <a className='nav-link' >
        <span className='ml-2'>about</span>
    </a>
</Link> 

如果您能帮助我,我会非常感激。

1 个答案:

答案 0 :(得分:0)

我将使用我的代码示例进行解释:

我的 package.json 包含此脚本:"build": "next build && next export"

当我运行时:npm run build NextJS 创建文件夹 out,例如: enter image description here

我创建了 next.config.js 并添加了下一个代码 from here

module.exports = {
    trailingSlash: true,
  }

并重新运行:npm run build

现在,文件夹 out 包含每个页面(路由)的子文件夹和创建的文件夹内的 index.html 文件。

enter image description here

我在 AWS S3 存储桶上托管,下一个屏幕截图:

enter image description here

如您所见,我上传了 out 文件夹中除 404 之外的所有子文件夹。 我将 index.html404 重命名为 404.html 并上传。

现在可以了。

缺点 - 在 S3 存储桶中上传许多文件夹不方便。