我做了一个向koa-router发送ajax请求,并且我想重定向'/',但是url没有改变。这是我的代码:使用koa-router redircet提交
router.post('/action',function *(next){
//some action
this.redirect('/');
});
我的愿望是 '/登录'=> '/',但URL didn`t变化, '/登录'=> '/登录'。 this is the result
我做了一个向koa-router发送ajax请求,并且我想重定向'/',但是url没有改变。这是我的代码:使用koa-router redircet提交
router.post('/action',function *(next){
//some action
this.redirect('/');
});
我的愿望是 '/登录'=> '/',但URL didn`t变化, '/登录'=> '/登录'。 this is the result
您无法通过ajax响应重定向浏览器。浏览器异步执行ajax请求,并且ajax响应中的Location: ...
标题将而不是更改浏览器URL。 ajax请求本身正被重定向到/
url,但不是您当前的浏览器窗口。
@jbielick是在正确的道路上:我不能想到任何情况下有意义在ajax请求中执行重定向。
无论如何,忘记ajax问题。还有一个更简单的方法做KOA路由器重定向
只需使用:
router.redirect('/action', '/');