Next.js页面在生产版本中以404结尾

reactjs React.js

老丝

2020-04-07

我已经建立了一个next.js应用程序。这些页面可以在开发环境中正常工作,但是如果我尝试运行生产版本,则只有index.js页面可以正确加载,所有其他页面都以404结尾。

npm run build输出以下内容:

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的下一个/链接,如果单击该链接,它将永远加载。如前所述,如果直接访问该页面将显示404。

EDIT: Also the console only displays Ready on http://localhost:3000 --> not showing any logs regarding building pages, not sure if this should happen in production or only in development.

第4123篇《Next.js页面在生产版本中以404结尾》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

1个回答
十三 2020.04.07

(由我自己回答)

问题在于大写的文件夹名称和文件(例如/ Product / Overview)在测试中没有问题,下一次直接路由到大小写是没有问题的。

执行构建的版本后,生产环境的文件系统接管了(在我的情况下为macOS),当时情况很重要。

通过小写/ pages目录中的所有内容来解决。

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android