【问题标题】:React Nodejs page blank on reload重新加载时反应Nodejs页面空白
【发布时间】:2021-09-18 18:36:15
【问题描述】:

我将我的第一个 MERN 项目投入生产。

问题是,例如,在重新加载时,我会得到一个 cannot GET /profile

我读到它来自 react-router-dom。

所以这是我应该处理的代码,但我无法成功:

if (process.env.NODE_ENV === 'production') {
    app.use(express.static('client/build'))
    app.get('*', (req, res) => {
        res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'))
    })
}

我知道第一行可以正常工作,但第二行会让一切崩溃。

有什么想法吗?

【问题讨论】:

  • 你能分享错误信息吗?
  • 你可以看到它:waletoo.herokuapp.com
  • 应用程序错误
  • 它对我有用
  • @PankajTanwar 因为我脱掉了第二行

标签: node.js reactjs react-router-dom production


【解决方案1】:

对于那些需要的人,我只是忘记了```const path = require('path')。

【讨论】:

    猜你喜欢
    • 2023-03-19
    • 1970-01-01
    • 2020-03-09
    • 1970-01-01
    • 1970-01-01
    • 2011-08-11
    • 1970-01-01
    • 2016-08-25
    • 2018-08-17
    相关资源
    最近更新 更多