Last active
April 1, 2021 07:08
-
-
Save srph/030db1525b411ada2252 to your computer and use it in GitHub Desktop.
axios + react-router: handling invalid tokens through axios interceptors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios from 'axios'; | |
import cookie from 'cookie-machine'; | |
import {hashHistory} from 'react-router'; | |
axios.interceptors.response.use(null, function(err) { | |
if ( err.status === 401 ) { | |
cookie.remove('my-token-key'); | |
hashHistory.push('/login'); | |
} | |
return Promise.reject(err); | |
}); |
Attempted import error: 'hashHistory' is not exported from 'react-router'.
in fact, I'm using "react-router-dom": "^5.2.0"
this solution seems to be outdated, so it is not working!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So easy, thanks it works great