E
E
Elena2021-01-15 14:02:14
React
Elena, 2021-01-15 14:02:14

How to redirect the user to the authorization page in the error interceptor?

There is an error handler like this:

axios.interceptors.response.use(function (response) {
  return response;
}, function (error) {
  if (error.response.status === 400) {
    что здесь написать?
  }
  return Promise.reject(error.response.data)
});

How to redirect user on 400 error? What should be used? history.push won't work

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander N, 2021-01-15
@Elena0394

In fact, if you do not need to save the store, then you can simply window.location.href = '/'
If not, then I would like to hear arguments against)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question