How the nuxt project uses the router.push () method in the plug-in axios route interception

how does the nuxt project use the router.push () method in plug-in axios route interception?

  $axios.interceptors.response.use(
    (response) => {
      if (response.data.code === 401) {
        Cookie.remove("token");
        Cookie.remove("username");
        Cookie.remove("login");
         Router.push("/users/login");
      }
      return response;
    },
  );

in this way, router will report an error. How can I correct it?

Sep.01,2021

now, instead of using router.push, directly, we use redirect

.
const { $axios, redirect, error } = obj;
 $axios.interceptors.response.use(
    (response) => {
      if (response.data.code === 401) {
        Cookie.remove('token');
        Cookie.remove('username');
        Cookie.remove('login');
        redirect(true, '/users/login');
      }
      return response;
    },
  );

window.$nuxt.$router.push ('/ login/')

Menu