Skip to content

Commit

Permalink
fix: 🐛生成路由出错问题
Browse files Browse the repository at this point in the history
  • Loading branch information
buqiyuan committed Dec 17, 2021
1 parent 061c6ed commit e164bf1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
27 changes: 17 additions & 10 deletions src/router/generator-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function filterAsyncRoute(
// 如果是页面
const Component = constantRouterComponents[viewPath] || NotFound;
route.component = Component;
const perms = routes.filter((n) => n.parentId === item.id).map((n) => n.perms.split(','));
const perms = routes.filter((n) => n.parentId === item.id).map((n) => n.perms?.split(','));
if (route.meta && perms) {
// 设置当前页面所拥有的权限
route.meta.perms = perms.flat(Infinity) as string[];
Expand All @@ -90,13 +90,20 @@ export const generatorDynamicRouter = (menus: API.Menu[]): RouteRecordRaw[] => {
// 后端数据, 根级树数组, 根级 PID
// listToTree(data, childrenNav, 0)
// rootRouter.children = childrenNav
const routeList = filterAsyncRoute(menus);
console.log(routeList, '根据后端返回的权限路由生成');
const layout = routes.find((item) => item.name == 'Layout')!;
layout.children = [...common, ...routeList, notFound];
// const routes = [...common,...routeList]
// routes.forEach(item => router.addRoute('Layout', item))
router.addRoute(layout);
// router.addRoute(notFound)
return layout.children;
try {
console.log('menus', menus);

const routeList = filterAsyncRoute(menus);
const layout = routes.find((item) => item.name == 'Layout')!;
console.log(routeList, '根据后端返回的权限路由生成');
layout.children = [...common, ...routeList, notFound];
// const routes = [...common,...routeList]
// routes.forEach(item => router.addRoute('Layout', item))
router.addRoute(layout);
// router.addRoute(notFound)
return layout.children;
} catch (error) {
console.error('生成路由时出错', error);
return [];
}
};
2 changes: 1 addition & 1 deletion src/views/shared/login/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
message.destroy();
});
message.success('登录成功!');
router.replace((route.query.redirect as string) ?? '/');
setTimeout(() => router.replace((route.query.redirect as string) ?? '/'));
} catch (error: any) {
Modal.error({
title: () => '提示',
Expand Down

0 comments on commit e164bf1

Please sign in to comment.