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');
}
});
}
If I load the page on '/', then navigate to '/one' and make an axios request, the onError interceptor will return '/' via route.fullPath.
It should return '/one'.
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
Hi @chrislentz I could not reproduce
Could you provide a repository?
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
This is not a bug. When destructing an object references are kept. @schellenbergk solution for app.router.currentRoute.path seems best :)
Most helpful comment
I got the same issue in my axios plugin:
route.pathseems to be set to the route when the plugin was initialized,app.router.currentRoute.pathseems correct