I am trying to get the current path through route.fullPath from within a Nuxt plugin for Axios. It is working to a degree, but it looks like because it is coming from the context, it is only ever setting the path when the page was initially loaded. How can I get the current route.fullPath (after any route changes) at the time of the Axios error to show?
export default function ({ $axios, store, route, redirect }) {
$axios.onError((error) => {
if (error.response.status === 401) {
store.commit('misc/setRedirect', route.fullPath);
redirect('/sign-in');
}
});
}