react-router

在组件外面进行路由跳转

[email protected]

router.js

import { createHashHistory } from "history"; // 或者createBrowserHistory

export default createHashHistory(); // 创建路由 提供给组件外的地方使用

request.js 无权限的时候在这里进行全局拦截

export const myAxios = axios.create();

myAxios.interceptors.response.use(
  function (response) {
    // Any status code that lie within the range of 2xx cause this function to trigger
    // Do something with response data
    if (response?.data?.code === 401) { 
      message.error("登录失效");
      store.remove("USER_TOKEN");
      history.push("/login");
    }
    return response;
  },
  function (error) {
    // Any status codes that falls outside the range of 2xx cause this function to trigger
    // Do something with response error
    console.warn(error);
    return Promise.reject(error);
  }
);

你可能感兴趣的:(react-router)