diff --git a/src/router/guards.js b/src/router/guards.js index 0b11204..4bf0e62 100644 --- a/src/router/guards.js +++ b/src/router/guards.js @@ -66,13 +66,21 @@ const authorityGuard = (to, from, next, options) => { */ const redirectGuard = (to, from, next, options) => { const {store} = options + const getFirstChild = (routes) => { + const route = routes[0] + if (!route.children || route.children.length === 0) { + return route + } + return getFirstChild(route.children) + } if (store.state.setting.layout === 'mix') { const firstMenu = store.getters['setting/firstMenu'] if (firstMenu.find(item => item.fullPath === to.fullPath)) { store.commit('setting/setActivatedFirst', to.fullPath) const subMenu = store.getters['setting/subMenu'] if (subMenu.length > 0) { - return next({path: subMenu[0].fullPath}) + const redirect = getFirstChild(subMenu) + return next({path: redirect.fullPath}) } } }