简体   繁体   English

重新加载时反应 Nodejs 页面空白

[英]React Nodejs page blank on reload

I pushed in production my first MERN project.我将我的第一个 MERN 项目投入生产。

The problem is, on reload i get a cannot GET /profile for example.问题是,例如,在重新加载时,我得到了一个cannot GET /profile的信息。

I read that it du to react-router-dom.我读到它是因为 react-router-dom。

So here is my code that should handle this, but I can't succeed :所以这是我的代码应该处理这个,但我不能成功:

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'))
    })
}

I know the first line works fine, but the second makes everything crash.我知道第一行工作正常,但第二行使一切崩溃。

Any idea ?任何想法 ?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM