我建立了一个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的next/link,如果点击会一直加载。正如所说,如果直接访问页面,则显示404错误。
编辑: 而且控制台只显示Ready on http://localhost:3000 -->没有显示任何关于页面构建的日志,不确定这是否应该发生在生产环境中还是只有在开发中才会出现。