How to redirect from axios interceptor with react Router V4?

后端 未结 8 2109
忘了有多久
忘了有多久 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:24

    The accepted answer doesnt solve my problem. After spending time in axios and tickets around interceptor not triggering, i found, axios doesnt support decorating interceptor globally like it is described above. for future readers, please keep in mind that, axios has tagged this global interceptor as feature. so maybe we will get it in the future realse. for ref: https://github.com/axios/axios/issues/993.

    I do have a single axios instance for all the api call, so i solved defining interceptor in it.

提交回复
热议问题