Current route.fullPath is out of date when called inside of an interceptor

chrislentz
0
chrislentz
commented 6 months ago

Version

v5.6.0

Steps to reproduce

Make an axios API call after a route change after the initial SSR app load.

export default function ({ $axios, store, route, redirect }) {
  $axios.onError((error) => {
    if (error.response.status === 401) {
      store.commit('misc/setRedirect', route.fullPath);

      redirect('/sign-in');
    }
  });
}

What is expected ?

If I load the page on '/', then navigate to '/one' and make an axios request, the onError interceptor will return '/' via route.fullPath.

What is actually happening?

It should return '/one'.

Additional comments?

I was able to find a workaround by using app instead of route, but I wanted to report the bug.

Workaround: app.router.currentRoute.fullPath

bug
0
ricardogobbosouza
1.1k
ricardogobbosouza
commented 6 months ago

Hi @chrislentz I could not reproduce
Could you provide a repository?

0
schellenbergk
0
schellenbergk
commented 5 months ago

I got the same issue in my axios plugin:

export default function({ $axios, app, route }) {
  $axios.onError(error => {
    if (error.response.status === 401) {
      console.log("Axios 401: ", app.router.currentRoute.path, route.path)
    }
  })
}

route.path seems to be set to the route when the plugin was initialized, app.router.currentRoute.path seems correct

0
Informations
Bug Report โ€ข Open
#c291 - Created 6 months ago