title: In Next.js, How to Redirect page in axios interceptor?
body: <p>I want to redirect page in axios interceptor.</p>
  <p>However, when  <strong>server-side rendering</strong>, <strong>I can't access to server side context in axios interceptor</strong>. So I try to use next/router. but it only works in client side.</p>
  <p>How can I this?</p>
  <p>Below is the function executed in the axios interceptor.</p>
  <pre class="lang-js prettyprint-override"><code>// customAxios.ts
  const customAxios = axios.create();
  
  customAxios.interceptors.response.use((response) =&gt; response, responseErrorHandler);
  </code></pre>
  <pre class="lang-js prettyprint-override"><code>// responseErrorHandler.ts
  const responseErrorHandler = (error: AxiosError): Promise&lt;AxiosError&gt; =&gt; {
    if (error.response) {
      if (error.message === TIMEOUT_MESSAGE) {
        if (typeof window === 'undefined') {
           // Redirect to /503 page in server side rendering
        } else {
          window.location.href = '/503';
        }
      }
    }
  
    return Promise.reject(error);
  }
  </code></pre>