【问题标题】:NextJS calling dynamic page on production redirects to rootNextJS 在生产中调用动态页面重定向到根目录
【发布时间】:2021-02-02 18:52:10
【问题描述】:

我想要什么

用户输入https://www.example.com/test,用户获取NextJS动态路由/test/index.js的内容。 这在本地有效。

会发生什么

用户输入https://www.example.com/test,用户获取根页面(index.js)的内容。 浏览器仍然显示https://www.example.com/test,但不是/test/index.js 的内容。 这只出现在生产中。

信息

  • 部署到 Firebase 托管。

【问题讨论】:

    标签: javascript reactjs firebase next.js firebase-hosting


    【解决方案1】:

    问题的根源在于,我正在导出 NextJS 应用程序并将输出用作 Firebase 的源文件。我的具体问题的解决方案是设置 Firebase 函数 以真正启用服务器端渲染,而不是显示提供的静态文件。这也解决了我的路由问题。

    一旦每个人使用不同的文件夹结构和方式来部署应用程序,我发现教程非常具有误导性。

    如果您遇到同样的问题,请随时查看my repository。它是 Firebase 配置、package.json 和服务器文件的组合 - 考虑到为开发和生产导出不同的文件夹路径。

    这些资源对我很有帮助:

    总体教程:https://itnext.io/deploying-next-js-app-to-firebase-functions-eb473791d79e - 这缺少一些关于函数名称的步骤。

    非常适合理解每个文件的作用:https://github.com/jthegedus/firebase-gcp-examples/tree/master/functions-nextjs

    很好理解渲染方式:https://codeburst.io/next-js-on-cloud-functions-for-firebase-with-firebase-hosting-7911465298f2

    这让我明白了如何正确使用 Firebase 函数名称:https://github.com/vercel/next.js/tree/canary/examples/with-firebase-hosting

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-06-19
      • 2018-04-04
      • 2019-02-08
      • 1970-01-01
      • 1970-01-01
      • 2017-05-01
      • 1970-01-01
      相关资源
      最近更新 更多