Skip to content

Commit 66f7746

Browse files
committed
!290 修复三级及以上菜单路由缓存失效问题
1 parent 2270753 commit 66f7746

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/store/modules/permission.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { constantRoutes } from '@/router'
2-
import { getRouters } from '@/api/menu'
1+
import {constantRoutes} from '@/router'
2+
import {getRouters} from '@/api/menu'
33
import Layout from '@/layout/index'
44
import ParentView from '@/components/ParentView';
5-
import { toCamelCase } from "@/utils";
5+
import {toCamelCase} from "@/utils";
66

77
const permission = {
88
state: {
@@ -28,15 +28,15 @@ const permission = {
2828
},
2929
actions: {
3030
// 生成路由
31-
GenerateRoutes({ commit }) {
31+
GenerateRoutes({commit}) {
3232
return new Promise(resolve => {
3333
// 向后端请求路由数据(菜单)
3434
getRouters().then(res => {
3535
const sdata = JSON.parse(JSON.stringify(res.data)) // 【重要】用于菜单中的数据
3636
const rdata = JSON.parse(JSON.stringify(res.data)) // 用于最后添加到 Router 中的数据
3737
const sidebarRoutes = filterAsyncRouter(sdata)
3838
const rewriteRoutes = filterAsyncRouter(rdata, false, true)
39-
rewriteRoutes.push({ path: '*', redirect: '/404', hidden: true })
39+
rewriteRoutes.push({path: '*', redirect: '/404', hidden: true})
4040
commit('SET_ROUTES', rewriteRoutes)
4141
commit('SET_SIDEBAR_ROUTERS', constantRoutes.concat(sidebarRoutes))
4242
commit('SET_DEFAULT_ROUTES', sidebarRoutes)
@@ -60,6 +60,11 @@ function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) {
6060
}
6161
// 路由地址转首字母大写驼峰,作为路由名称,适配 keepAlive
6262
route.name = toCamelCase(route.path, true)
63+
// 处理三级及以上菜单路由缓存问题,将path名字赋值给name
64+
if (route.path.indexOf("/") !== -1) {
65+
var pathArr = route.path.split("/")
66+
route.name = toCamelCase(pathArr[pathArr.length - 1], true)
67+
}
6368
route.hidden = !route.visible
6469
// 处理 component 属性
6570
if (route.children) { // 父节点
@@ -86,10 +91,10 @@ function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) {
8691
}
8792

8893
function filterChildren(childrenMap, lastRouter = false) {
89-
let children = []
94+
var children = []
9095
childrenMap.forEach((el, index) => {
9196
if (el.children && el.children.length) {
92-
if (el.component === 'ParentView' && !lastRouter) {
97+
if (!el.component && !lastRouter) {
9398
el.children.forEach(c => {
9499
c.path = el.path + '/' + c.path
95100
if (c.children && c.children.length) {

0 commit comments

Comments
 (0)