萤火科技 1 жил өмнө
parent
commit
5e767ead72

+ 18 - 14
src/permission.js

@@ -32,20 +32,24 @@ router.beforeEach((to, from, next) => {
           .dispatch('GetInfo')
           .then(data => {
             const roles = data.roles
-            store.dispatch('GenerateRoutes', { roles }).then(() => {
-              // 根据roles权限生成可访问的路由表
-              // 动态添加可访问路由表
-              router.addRoutes(store.getters.addRouters)
-              // 请求带有 redirect 重定向时,登录自动重定向到该地址
-              const redirect = decodeURIComponent(from.query.redirect || to.path)
-              if (to.path === redirect) {
-                // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record
-                next({ ...to, replace: true })
-              } else {
-                // 跳转到目的路由
-                next({ path: redirect })
-              }
-            })
+            store.dispatch('GenerateRoutes', { roles })
+              .then(routers => {
+                // 根据roles权限生成可访问的路由表
+                // 动态添加可访问路由表
+                // router.addRoutes(routers)
+                for (let x of routers) {
+                  router.addRoute(x)
+                }
+                // 请求带有 redirect 重定向时,登录自动重定向到该地址
+                const redirect = decodeURIComponent(from.query.redirect || to.path)
+                if (to.path === redirect) {
+                  // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record
+                  next({ ...to, replace: true })
+                } else {
+                  // 跳转到目的路由
+                  next({ path: redirect })
+                }
+              })
           })
           .catch(err => {
             // notification.error({

+ 1 - 1
src/store/modules/permission.js

@@ -75,7 +75,7 @@ const permission = {
         // 改写直接使用路由配置
         const accessedRouters = asyncRouterMap
         commit('SET_ROUTERS', accessedRouters)
-        resolve()
+        resolve(accessedRouters)
       })
     }
   }