From e164bf17b6a9f905c5c78b51b2a46b54ff554077 Mon Sep 17 00:00:00 2001 From: bqy_fe <1743369777@qq.com> Date: Fri, 17 Dec 2021 10:47:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20:bug:=E7=94=9F=E6=88=90=E8=B7=AF?= =?UTF-8?q?=E7=94=B1=E5=87=BA=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/generator-router.tsx | 27 +++++++++++++++++---------- src/views/shared/login/index.vue | 2 +- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/router/generator-router.tsx b/src/router/generator-router.tsx index b82b0e53f..50ebd16a6 100644 --- a/src/router/generator-router.tsx +++ b/src/router/generator-router.tsx @@ -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[]; @@ -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 []; + } }; diff --git a/src/views/shared/login/index.vue b/src/views/shared/login/index.vue index f89a83a71..4cf42d2ed 100644 --- a/src/views/shared/login/index.vue +++ b/src/views/shared/login/index.vue @@ -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: () => '提示',