1. After sending the superagent request, process the data in the background, and then choose whether to redirect based on the results but it always fails.
2. The code is as follows:
//superagent请求
request.get(`/allStudios`)
.end((err,res) =>{
next({type:'ALL_STUDIOS',content:res.body})
});
//后台处理
router.get('/allStudios',(req,res,next)=>{
Studios.find({},(err,data)=>{
if(req.headers.cookie){
res.send(data);
}
else {
res.redirect(302,'http://localhost:3000');
}
})
});
3. The result is that there is no way to implement redirection
Please help me solve it, thank you!
ajax
cannot be redirected, but you can make your own judgment after getting the data at the front end. If you need to redirect, usewindow.location.href = 'new address'
to jump.