首页 > koa-router如何跳转页面?

koa-router如何跳转页面?

koa-router 如何跳转url,比如登录成功后跳转到首页,怎么实现啊?


res.redirect(url, [alt])

重定向到对应 url。

字符串 "back" 是一个特殊参数,其提供了 Referrer 支持。当没有Referrer时,使用 alt 或者 / 代替。

this.redirect('back');
this.redirect('back', '/index.html');
this.redirect('/login');
this.redirect('http://google.com');
直接在重定向之前或者之后执行即可。如果要修改 body,需要在重定向之前执行。

this.status = 301;
this.redirect('/cart');
this.body = 'Redirecting to home page';
【热门文章】
【热门文章】