How to redirect a user inside an http interceptor vue resource?

I want to redirect the user when I have 401, but I cannot access the router from this context:

  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 } }); }); 

How can i do this?

Usage: Vue-router and Vue-resource

+5
source share
1 answer
 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(...) } }); }); 
+3
source

Source: https://habr.com/ru/post/1266246/


All Articles