我已经构建了next.js应用程序。 这些页面在开发环境中工作正常,但是如果我尝试运行生产版本,则只有index.js页面被正确加载,所有其他页面都以404结尾。 / p>
npm run构建输出以下内容:
reating an optimized production build ...
Compiled successfully.
Warning: You have opted-out of Automatic Prerendering due to `getInitialProps` in `pages/_app`.
Read more: https://err.sh/next.js/opt-out-automatic-prerendering
Page Size Files Packages
┌ σ / 66.8 kB 4 27
├ /_app 17.9 kB 0 31
├ /_document
├ /_error 397 B 0 27
├ σ /Products/[specificPage]/Dashboard 404 B 4 27
├ σ /Products/Overview 95.1 kB 9 30
├ σ /Products/Roadmap 475 B 4 27
├ σ /Strategy/Goals 451 B 4 27
└ σ /Strategy/Metrics 459 B 4 27
因此,我认为页面构建正确。现在这让我很困惑。
在我的index.js页面中,有一个指向/ strategy / goals的next /链接,如果单击该链接,则该链接将永远加载。如前所述,如果直接访问该页面,则会显示404。
编辑: 此外,控制台仅在http://localhost:3000上显示“就绪”->不显示有关构建页面的任何日志,不确定是否应该在生产中或仅在开发中发生。
答案 0 :(得分:1)
(由我自己回答)
问题在于文件夹名称和文件(例如,/ Product / Overview)大写,这在接下来的测试中没有问题,直接路由到大小写是没有问题的。
执行生成的版本后,生产环境的文件系统接管了(我的情况是macOS)。
通过将/ pages目录中的所有内容都改小写来解决。