问题描述
1.在发送superagent请求之后,后台处理数据,然后根据结果选择是否需要重定向但是一直失败。2.代码如下:
//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.结果是没办法实现重定向
请大家帮忙解决,谢谢!
问题解答
回答1:ajax是不能重定向的,但是你可以在前端拿到数据后,自己做个判断,如果需要重定向的,通过window.location.href = ’新地址’来跳转。