[英]Express Routes for ejected create-react-app
I want to serve another static page for the route "/about", now I have : 我想为“ / 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'));
});
and I also have a post request 而且我还有一个职位要求
app.post('/getfrontpage', (req, res) => {
console.log("FIRST PAGE", req.body.params.page)
});
The post request works, I use axios to make a call, but the "/about" route doesn't work when I'm changing the url 发布请求有效,我使用axios拨打电话,但更改网址时“ / about”路由不起作用
Do you have any errors on the server side? 您在服务器端是否有任何错误?
The example above works for me: https://runkit.com/dionnis/5ab936152f32d7001211d85f 上面的示例对我有用 : https : //runkit.com/dionnis/5ab936152f32d7001211d85f
Note: I changed app.post('/getfrontpage'
to app.get('/getfrontpage'
注意:我将
app.post('/getfrontpage'
更改为app.get('/getfrontpage'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.