I want to make a redirection in axios interceptors when receiving a 403 error. But how can I access the history outside React components ?
In Navigating Programatically
This works perfectly.
window.location.href = `${process.env.REACT_APP_BASE_HREF}/login`;
import { createHashHistory } from 'history' // or createBrowserHistory const history = createHashHistory() if (response.status === 403) { history.push('/login') }
ReactTraining/history