【发布时间】: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