Axios interceptors based on version #1241
-
In my brand new Laravel project (using Vite, which may be relevant), I had Perhaps a dumb question, but should that matter? axios.interceptors.response.use(response => {
console.log('intercepted')
}) Using that snippet, each changing of page and request will log correctly when I install |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
I'm running into the same issue at the moment. I'm hoping to be able to continue to use version 0.27 for my manual calls, and then tap into 0.21 with interceptors for Inertia specific calls (as that's the version it currently ships with). Currently, running the same version of Axios (0.21) as Inertia is the only way I can get this to work. I believe Axios is going away in Inertia though. I really hope whatever replaces it has something like interceptors as well as I rely on them quite a bit. |
Beta Was this translation helpful? Give feedback.
-
It's because with multiple version your bundler will include two different versions of axios on the same page, each are completely different instances and why interceptors don't work If using webpack add resolve: {
alias: {
//...
axios: path.resolve('node_modules/axios/dist/axios.js'),
},
}, And then you can use whatever version you like, only one will be bundled |
Beta Was this translation helpful? Give feedback.
It's because with multiple version your bundler will include two different versions of axios on the same page, each are completely different instances and why interceptors don't work
If using webpack add
And then you can use whatever version you like, only one will be bundled