l8l8
import { getUserPerm } from \'@/services/menu\';
import router from \'umi/router\';
let authRoutes = [];
export const dva = {
  config: {
    onError(err) {
      err.preventDefault();
      console.error(err.message);
    },
  },
};

function filterRoute(routes,authRoute) {
  const arr = [];
  authRoute.forEach(item => {
    routes.forEach(route => {
      if (route.path === item.path) {
        let obj = {};
        if (route.routes && item.routes) {
          obj = route;
          obj.routes = (filterRoute(route.routes,item.routes));
          arr.push(obj);
        } else {
          obj = route;
          arr.push(obj);
        }
      }
    })
  })
  return arr;
}
export function patchRoutes(routes) {
 routes[1].routes = filterRoute(routes[1].routes,authRoutes)
  window.g_routes = routes;
}
export async function  render(oldRender) {
  const authRoutesResult = await getUserPerm();
  window.oldRender = () => {
    if (authRoutesResult && authRoutesResult.code === 0) {
      authRoutes = authRoutesResult.data;
    } else {
      oldRender();
    }
    oldRender();
  }
  if (window.oldRender) {
    window.oldRender();
  }
}

在model里登陆和登出需要window.location.reload 刷新页面。

分类:

技术点:

相关文章:

  • 2021-07-11
  • 2022-01-01
  • 2021-10-19
  • 2021-12-27
  • 2022-01-04
  • 2022-12-23
  • 2021-11-14
  • 2021-11-01
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-28
  • 2021-12-13
相关资源
相似解决方案