title: React router v6 how to use `navigate` redirection in axios interceptor
body: <pre><code>import axios from &quot;axios&quot;;
  import { useNavigate } from &quot;react-router-dom&quot;;
  
  export const api = axios.create({
    baseURL: &quot;http://127.0.0.1:8000/&quot;,
    headers: {
      &quot;content-type&quot;: &quot;application/json&quot;,
    },
  });
  
  api.interceptors.response.use(
    function (response) {
      return response;
    },
    function (er) {
      if (axios.isAxiosError(er)) {
        if (er.response) {
          if (er.response.status == 401) {
  
            // Won't work
            useNavigate()(&quot;/login&quot;);
  
          }
        }
      }
  
      return Promise.reject(er);
    }
  );
  </code></pre>