How to redirect from axios interceptor with react Router V4?

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

    This seems to work for me

     function (error) {
                var accessDenied = error.toString().indexOf("401");
                if (accessDenied !== -1) {
                  console.log('ACCESS DENIED')
                  return window.location.href = '/accessdenied'
                }
              });
    

提交回复
热议问题