Browse Source

[fix][micro-ui]fix loadMenus function bug,modify router/index.js

Signed-off-by: AllData科学护城河作者 <m13602574132@163.com>
AllData科学护城河作者 1 year ago
parent
commit
e123744dc5
1 changed files with 15 additions and 0 deletions
  1. 15 0
      studio/micro-ui/src/router/index.js

+ 15 - 0
studio/micro-ui/src/router/index.js

@@ -10,6 +10,21 @@ import { filterAsyncRouter } from '@/store/modules/permission'
 NProgress.configure({ showSpinner: false })// NProgress Configuration
 
 const whiteList = ['/login']// no redirect whitelist
+export const loadMenus = (next, to) => {
+  buildMenus().then(res => {
+    const sdata = JSON.parse(JSON.stringify(res))
+    const rdata = JSON.parse(JSON.stringify(res))
+    const sidebarRoutes = filterAsyncRouter(sdata)
+    const rewriteRoutes = filterAsyncRouter(rdata, false, true)
+    rewriteRoutes.push({ path: '*', redirect: '/404', hidden: true })
+
+    store.dispatch('GenerateRoutes', rewriteRoutes).then(() => { // 存储路由
+      router.addRoutes(rewriteRoutes) // 动态添加可访问路由表
+      next({ ...to, replace: true })
+    })
+    store.dispatch('SetSidebarRouters', sidebarRoutes)
+  })
+}
 
 router.beforeEach((to, from, next) => {
   if (to.meta.title) {