i need to use $router.push in Vue-router. Check my code:
axios.interceptors.response.use(function (response) {
return response
}, function (error) {
if(error && error.message === 'Network Error'){
//here is problem. I can;t use this.$router in js file? How to fix this?
this.$router.push('calendar')
}
return Promise.reject(error)
})
My question is how do I use $router.push in this file? Check my router:
import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import axios from 'axios'
Vue.use(VueRouter);
axios.interceptors.response.use(function(response) {
return response
}, function(error) {
if (error && error.message === 'Network Error') {
Vue.push('home')
}
return Promise.reject(error)
})
const routes = [{
path: '/',
name: 'home',
component: Home
}, {
other routes
}]