umi 动态路由配置
Posted l8l8
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了umi 动态路由配置相关的知识,希望对你有一定的参考价值。
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 刷新页面。
以上是关于umi 动态路由配置的主要内容,如果未能解决你的问题,请参考以下文章