Commit 464dc789 authored by 张伯涛's avatar 张伯涛

不管是几级菜单,登录时都会显示第一个目录下的最小一级菜单

parent 525338ab
...@@ -12,6 +12,14 @@ NProgress.configure({ showSpinner: false }) // NProgress Configuration ...@@ -12,6 +12,14 @@ NProgress.configure({ showSpinner: false }) // NProgress Configuration
const whiteList = ['/auth-redirect', '/bind', '/register', '/login', '/forgetPwd'] const whiteList = ['/auth-redirect', '/bind', '/register', '/login', '/forgetPwd']
/** 获取路由当中第一个目录下的最小一级菜单*/
export function getChildPath(item) {
if (item[0].children && item[0].children.length > 0) {
return getChildPath(item[0].children)
} else {
return item[0].path
}
}
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
NProgress.start() NProgress.start()
...@@ -36,9 +44,9 @@ router.beforeEach((to, from, next) => { ...@@ -36,9 +44,9 @@ router.beforeEach((to, from, next) => {
// store.dispatch('permission/generateRoutes', { roles }).then(accessRoutes => { // store.dispatch('permission/generateRoutes', { roles }).then(accessRoutes => {
// 根据roles权限生成可访问的路由表 // 根据roles权限生成可访问的路由表
router.addRoutes(routers.accessedRoutes) // 动态添加可访问路由表 router.addRoutes(routers.accessedRoutes) // 动态添加可访问路由表
if (to.path === '/controlPlatform/control') { if (to.path === '/controlPlatform/control') {
next({ path: routers.accessedRoutes[0].children[0].path, replace: true }) getChildPath(routers.accessedRoutes) // 获取路由当中第一个目录下的最小一级菜单,登陆后自动跳转到第一个目录下的最小一级菜单
next({ path: getChildPath(routers.accessedRoutes), replace: true })
} else { } else {
next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment