我想尝试这条路线:GET / exercisesadd?id = google-oauth2%7C10385839303782
FrontEnd:
getResults: function(){
console.log(this.state.profile.user_id)
return axios.get('/exercisesadd', {
params: {
id: this.state.profile.user_id
}
})
.then(function(response){
return response;
});
}
服务器有:
app.get('/exercisesadd/:id', (req, res) => {
console.log(req.params)
});
答案 0 :(得分:0)
在您的情况下,您正在进行查询请求,但您的服务器没有查询请求的路由。
当您在服务器中进行GET /exercisesadd?id=google-oauth2%7C10385839303782
时,您必须拥有/exercisesadd?id
的路线,您只能拥有参数的路径
试试这个并查看控制台
app.get('/exercisesadd/:id?', (req, res) => {
console.log('Query', req.query, 'Params', req.params)
res.send(req.params);
});
获取localhost:3000/exercisesadd?id=google-oauth2%7C10385839303782
req.query
将为您提供{ id: 'google-oauth2|10385839303782' }
和
获取localhost:3000/exercisesadd/13134124252
req.params
将为您提供{ id: '13134124252' }