diff --git a/src/permission.ts b/src/permission.ts index 006266c..7584ebb 100644 --- a/src/permission.ts +++ b/src/permission.ts @@ -40,24 +40,14 @@ router.beforeEach(async (to, from, next) => { router.addRoute(INDEX_ROUTE) routes.forEach((route: any) => { // 动态添加可访问路由表 - try { - if (!route) { + if (!route.children) { + if (route.meta.type === MenuEnum.CATALOGUE) { return } - if (!route.path || !route.name) { - return - } - if (!route.children) { - if (route.meta?.type === MenuEnum.CATALOGUE) { - return - } - router.addRoute(INDEX_ROUTE_NAME, route) - return - } - router.addRoute(route) - } catch (error) { - console.error('添加路由失败:', error) + router.addRoute(INDEX_ROUTE_NAME, route) + return } + router.addRoute(route) }) next({ ...to, replace: true }) return diff --git a/src/router/index.ts b/src/router/index.ts index 7df566c..d565c51 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -12,21 +12,18 @@ export function getModulesKey() { } export function createRouteRecord(menus) { - // 过滤掉null或undefined的菜单项 - const validMenus = menus.filter(menu => menu != null) - - return validMenus.map(menu => { + return menus.map(menu => { const routeRecord: RouteRecordRaw = { - path: menu.paths || '/', - name: Symbol(menu.paths || Math.random().toString()), + path: menu.paths, + name: Symbol(menu.paths), meta: { hidden: !menu.isShow, keepAlive: !!menu.isCache, - title: menu.menuName || '', + title: menu.menuName, perms: menu.perms, icon: menu.icon, type: menu.menuType, - openOutside: menu.openOutside, + openOutside:menu.openOutside, openNewPage: menu.openNewPage } } @@ -35,13 +32,10 @@ export function createRouteRecord(menus) { routeRecord.component = LAYOUT break case MenuEnum.MENU: - routeRecord.component = loadRouteView(menu.component || '') - break - default: - routeRecord.component = RouterView + routeRecord.component = loadRouteView(menu.component) break } - if (menu.children && menu.children.length) { + if (menu.children.length) { routeRecord.children = createRouteRecord(menu.children) } return routeRecord @@ -51,13 +45,6 @@ export function createRouteRecord(menus) { // 动态加载组件 function loadRouteView(component: string) { try { - // 检查是否是URL类型的组件路径 - if (component.startsWith('http://') || component.startsWith('https://')) { - // 对于URL类型的组件,返回RouterView作为占位符 - // 实际的URL打开会通过openOutside或openNewPage处理 - return RouterView - } - const key = Object.keys(modules).find((key) => { return key.includes(`${component}.vue`) })