react-router

在组件外面进行路由跳转

react-router@5.x

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);
  }
);
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容