问题刷新页面nodejs无法/获取错误

tim*_*tim 1 production node.js express reactjs react-navigation

我已经建立了一个网站,当我在主页上刷新时,它很好,但是当我导航到其他页面时,它也很好,但是当我刷新这些其他页面时

\n
Cannot GET /otherpage\n
Run Code Online (Sandbox Code Playgroud)\n

我正在使用反应导航,如果我超链接它,我认为它可能也不起作用。

\n
\n\xef\xbb\xbfrequire('rootpath')();\nconst express = require('express');\nconst app = express();\n///\n///\napp.use('/accounts', require('./accounts/accounts.controller'));\n\nif(process.env.NODE_ENV === 'production'){\n \n  app.use(express.static('build'));\n\n \n\n  }\n
Run Code Online (Sandbox Code Playgroud)\n
server.js\nbuild\n
Run Code Online (Sandbox Code Playgroud)\n

文件目录

\n

我该如何解决这个问题?

\n

N. *_*ers 6

// Serve the static files from the React app
app.use(express.static(path.join(__dirname, 'client/build')));

// An api endpoint that returns a short list of items
app.get('/api/getList', (req,res) => {
    var list = ["item1", "item2", "item3"];
    res.json(list);
    console.log('Sent list of items');
});

// Handles any requests that don't match the ones above
app.get('*', (req,res) =>{
    res.sendFile(path.join(__dirname+'/client/build/index.html'));
});
Run Code Online (Sandbox Code Playgroud)

按照本教程进行进一步说明:https://dev.to/nburgess/creating-a-react-app-with-react-router-and-an-express-backend-33l3