Browse Source

fix: dynamic router generator

Sendya 5 years ago
parent
commit
0f096d4e5f
1 changed files with 10 additions and 4 deletions
  1. 10 4
      src/router/generator-routers.js

+ 10 - 4
src/router/generator-routers.js

@@ -1,7 +1,7 @@
 // eslint-disable-next-line
 import * as loginService from '@/api/login'
 // eslint-disable-next-line
-import { BasicLayout, RouteView, BlankLayout, PageView } from '@/layouts'
+import { BasicLayout, BlankLayout, PageView, RouteView } from '@/layouts'
 
 // 前端路由表
 const constantRouterComponents = {
@@ -116,12 +116,18 @@ export const generator = (routerMap, parent) => {
       // 路由名称,建议唯一
       name: item.name || item.key || '',
       // 该路由对应页面的 组件 :方案1
-      component: constantRouterComponents[item.component || item.key],
+      // component: constantRouterComponents[item.component || item.key],
       // 该路由对应页面的 组件 :方案2 (动态加载)
-      // component: constantRouterComponents[item.component || item.key] || () => import(`@/views/${item.component}`),
+      component: (constantRouterComponents[item.component || item.key]) || (() => import(`@/views/${item.component}`)),
 
       // meta: 页面标题, 菜单图标, 页面权限(供指令权限用,可去掉)
-      meta: { title: title, icon: icon || undefined, hiddenHeaderContent: hiddenHeaderContent, target: target, permission: item.name }
+      meta: {
+        title: title,
+        icon: icon || undefined,
+        hiddenHeaderContent: hiddenHeaderContent,
+        target: target,
+        permission: item.name
+      }
     }
     // 是否设置了隐藏菜单
     if (show === false) {