tim*_*tim 1 production node.js express reactjs react-navigation
我已经建立了一个网站,当我在主页上刷新时,它很好,但是当我导航到其他页面时,它也很好,但是当我刷新这些其他页面时
\nCannot GET /otherpage\nRun 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 }\nRun Code Online (Sandbox Code Playgroud)\nserver.js\nbuild\nRun Code Online (Sandbox Code Playgroud)\n文件目录
\n我该如何解决这个问题?
\n// 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
| 归档时间: |
|
| 查看次数: |
1382 次 |
| 最近记录: |