优化当动态路由数据为空时,页面登录后的跳转逻辑

This commit is contained in:
hooray
2021-04-20 19:27:58 +08:00
parent 79e30c80dc
commit 01c9ee9752
2 changed files with 8 additions and 6 deletions
+7 -5
View File
@@ -172,11 +172,13 @@ router.beforeEach(async(to, from, next) => {
replace: true
})
} else if (!store.state.settings.enableDashboard && to.name == 'dashboard') {
// 如果未开启控制台页面,则默认进入侧边栏导航第一个模块
next({
name: store.getters['menu/sidebarRoutes'][0].name,
replace: true
})
// 如果未开启控制台页面,则默认进入侧边栏导航第一个模块,但如果侧边栏导航没有模块,则还是进入控制台页面
if (store.getters['menu/sidebarRoutes'].length > 0) {
next({
name: store.getters['menu/sidebarRoutes'][0].name,
replace: true
})
}
}
} else {
// 如果是通过 name 跳转,并且 name 对应的路由没有权限时,需要做这步处理,手动指向到 404 页面
+1 -1
View File
@@ -102,7 +102,7 @@ const state = {
const getters = {
sidebarRoutes: state => {
return state.routes[state.headerActived].children
return state.routes.length > 0 ? state.routes[state.headerActived].children : []
}
}