How to redirect from axios interceptor with react Router V4?

后端 未结 8 2108
忘了有多久
忘了有多久 2021-01-30 17:36

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

8条回答
  •  走了就别回头了
    2021-01-30 18:42

    import { createHashHistory } from 'history' // or createBrowserHistory
    const history = createHashHistory()
    
    if (response.status === 403) {
      history.push('/login')
    }
    
    

    ReactTraining/history

提交回复
热议问题