[英]Express Routes for ejected create-react-app
我想為“ / about”路線提供另一個靜態頁面,現在我有了:
app.use(express.static(path.resolve(__dirname, '..', 'build')));
app.get('/', (req, res) => {
res.sendFile(path.resolve(__dirname, '..', 'build', 'index.html'));
});
app.get('/about', function (req, res) {
console.log("here")
res.sendFile(path.resolve(__dirname, '..', 'build', 'about.html'));
});
而且我還有一個職位要求
app.post('/getfrontpage', (req, res) => {
console.log("FIRST PAGE", req.body.params.page)
});
發布請求有效,我使用axios撥打電話,但更改網址時“ / about”路由不起作用
您在服務器端是否有任何錯誤?
上面的示例對我有用 : https : //runkit.com/dionnis/5ab936152f32d7001211d85f
注意:我將app.post('/getfrontpage'
更改為app.get('/getfrontpage'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.