mirror of
https://gitee.com/fantastic-admin/basic.git
synced 2024-12-02 03:57:37 +08:00
修复开启切换侧边栏同时跳转页面的配置项后无法跳转的问题
This commit is contained in:
parent
5fbb0130cf
commit
56d67ddd6b
@ -74,7 +74,7 @@ provide('switchMenu', switchMenu)
|
||||
function switchMenu(index) {
|
||||
store.commit('menu/switchHeaderActived', index)
|
||||
if (store.state.settings.switchSidebarAndPageJump) {
|
||||
router.push(store.getters['menu/sidebarRoutes'][0].path)
|
||||
router.push(store.getters['menu/sidebarRoutesFirstDeepestPath'])
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
@ -2,7 +2,6 @@ import { createRouter, createWebHashHistory } from 'vue-router'
|
||||
import store from '@/store'
|
||||
import NProgress from 'nprogress'
|
||||
import 'nprogress/nprogress.css' // progress bar style
|
||||
import path from 'path-browserify'
|
||||
|
||||
// 固定路由
|
||||
const constantRoutes = [
|
||||
@ -127,31 +126,8 @@ router.beforeEach(async(to, from, next) => {
|
||||
} else if (!store.state.settings.enableDashboard && to.name == 'dashboard') {
|
||||
// 如果未开启控制台页面,则默认进入侧边栏导航第一个模块
|
||||
if (store.getters['menu/sidebarRoutes'].length > 0) {
|
||||
// 此处没有使用 store.getters['menu/sidebarRoutes'][0].path 直接进行跳转是因为会有个隐性 bug ,即当父级路由如果设置了 redirect ,而 redirect 对应的嵌套子路由由于没有权限导致没有被注册,此时则会无限进入 404 页面
|
||||
let getDeepestPath = (routes, rootPath = '') => {
|
||||
let retnPath
|
||||
if (routes.children) {
|
||||
if (
|
||||
routes.children.some(item => {
|
||||
return item.meta.sidebar != false
|
||||
})
|
||||
) {
|
||||
for (let i = 0; i < routes.children.length; i++) {
|
||||
if (routes.children[i].meta.sidebar != false) {
|
||||
retnPath = getDeepestPath(routes.children[i], path.resolve(rootPath, routes.path))
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
retnPath = getDeepestPath(routes.children[0], path.resolve(rootPath, routes.path))
|
||||
}
|
||||
} else {
|
||||
retnPath = path.resolve(rootPath, routes.path)
|
||||
}
|
||||
return retnPath
|
||||
}
|
||||
next({
|
||||
path: getDeepestPath(store.getters['menu/sidebarRoutes'][0]),
|
||||
path: store.getters['menu/sidebarRoutesFirstDeepestPath'],
|
||||
replace: true
|
||||
})
|
||||
} else {
|
||||
|
@ -114,6 +114,29 @@ function flatAsyncRoutes(routes, breadcrumb, baseUrl = '') {
|
||||
return res
|
||||
}
|
||||
|
||||
function getDeepestPath(routes, rootPath = '') {
|
||||
let retnPath
|
||||
if (routes.children) {
|
||||
if (
|
||||
routes.children.some(item => {
|
||||
return item.meta.sidebar != false
|
||||
})
|
||||
) {
|
||||
for (let i = 0; i < routes.children.length; i++) {
|
||||
if (routes.children[i].meta.sidebar != false) {
|
||||
retnPath = getDeepestPath(routes.children[i], path.resolve(rootPath, routes.path))
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
retnPath = getDeepestPath(routes.children[0], path.resolve(rootPath, routes.path))
|
||||
}
|
||||
} else {
|
||||
retnPath = path.resolve(rootPath, routes.path)
|
||||
}
|
||||
return retnPath
|
||||
}
|
||||
|
||||
const state = () => ({
|
||||
isGenerate: false,
|
||||
routes: [],
|
||||
@ -138,6 +161,9 @@ const getters = {
|
||||
},
|
||||
sidebarRoutes: (state, getters) => {
|
||||
return getters.routes.length > 0 ? getters.routes[state.headerActived].children : []
|
||||
},
|
||||
sidebarRoutesFirstDeepestPath: (state, getters) => {
|
||||
return getDeepestPath(getters.sidebarRoutes[0])
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user