How to use this.$route into boot / axios.js
-
Hello guys!
I need to use the routing for the login route when I receive the 401 error, as shown below:
(Any idea?)import Vue from 'vue' import axios from 'axios' import { Notify } from 'quasar' const axiosInstance = axios.create({ baseURL: process.env.API }) axiosInstance.interceptors.response.use(response => { return response }, error => { if (error.response.status === 401) { Notify.create({ type: 'negative', timeout: 1000, position: 'top', message: error.response.data.message }) this.$router.push('/login') <<== HERE IS THE PROBLEM!!!! } }) Vue.prototype.$axios = axiosInstance export { axiosInstance }
Thanks!
-
That isn’t a boot file. Read and understand about them.
https://quasar.dev/quasar-cli/boot-files#Introduction
Scott