No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    How to use this.$route into boot / axios.js

    Framework
    2
    2
    544
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      mflorindo last edited by

      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!

      1 Reply Last reply Reply Quote 0
      • s.molinari
        s.molinari last edited by

        That isn’t a boot file. Read and understand about them.

        https://quasar.dev/quasar-cli/boot-files#Introduction

        Scott

        1 Reply Last reply Reply Quote 0
        • First post
          Last post