如何在vue-resource http拦截器内重定向用户?

thu*_*hur 8 vue-resource vue-router vuejs2

我想在有401时重定向用户,但我无法router从这个上下文访问:

  Vue.http.interceptors.push(function(request, next) {
    // continue to next interceptor
    next(function(response) {
        if(response.status == 401){
            //redirect user here
            //tried: Vue.$router and Vue.$route 
        }

    });
  });
Run Code Online (Sandbox Code Playgroud)

我该怎么做?

使用:Vue-router和Vue-resource

Ber*_*ert 8

const router = new VueRouter({
  routes
})

Vue.http.interceptors.push(function(request, next) {
    // continue to next interceptor
    next(function(response) {
        if(response.status == 401){
            router.push(...) 
        }
    });
 });
Run Code Online (Sandbox Code Playgroud)