Commit f7a5f7c8 by xinla

面包屑404问题,路由递归优化、支持无限级路由

1 parent aabca122
......@@ -10,7 +10,11 @@
</el-breadcrumb-item>
<el-breadcrumb-item v-for="(item, index) in levelList" :key="item.path">
<span
v-if="item.redirect === 'noRedirect' || index == levelList.length - 1"
v-if="
item.redirect === 'noRedirect' ||
index == levelList.length - 1 ||
!/^\//gi.test(item.redirect)
"
class="no-redirect"
>{{ item.meta.title }}</span
>
......@@ -35,7 +39,7 @@ import pathToRegexp from 'path-to-regexp'
export default {
data() {
return {
levelList: null,
levelList: null
}
},
watch: {
......@@ -46,12 +50,12 @@ export default {
}
this.$store.state.app.busininessDesc = ''
this.getBreadcrumb()
},
}
},
computed: {
busininessDesc() {
return this.$store.state.app.busininessDesc
},
}
},
created() {
this.getBreadcrumb()
......@@ -87,13 +91,15 @@ export default {
},
handleLink(item) {
const { redirect, path } = item
console.log(redirect, 'redirect')
if (redirect) {
this.$router.push(redirect)
return
}
console.log(this.pathCompile(path))
this.$router.push(this.pathCompile(path))
},
},
}
}
}
</script>
......@@ -106,7 +112,7 @@ export default {
margin-left: 8px;
.no-redirect {
color: $blue;
color: #999;
cursor: text;
}
}
......
......@@ -6,13 +6,13 @@ import View from '@/layout/components/View'
const permission = {
state: {
routes: [],
addRoutes: [],
addRoutes: []
},
mutations: {
SET_ROUTES: (state, routes) => {
state.addRoutes = routes
state.routes = constantRoutes.concat(routes)
},
}
},
actions: {
// 生成路由
......@@ -26,20 +26,22 @@ const permission = {
resolve(accessedRoutes)
})
})
},
},
}
}
}
// 遍历后台传来的路由字符串,转换为组件对象
function filterAsyncRouter(asyncRouterMap, level) {
return asyncRouterMap.filter((route) => {
let level = 0
function filterAsyncRouter(asyncRouterMap) {
level++
let res = asyncRouterMap.filter((route) => {
if (route.component) {
// Layout组件特殊处理
if (route.component === 'Layout') {
if (route.redirect === 'noRedirect' && route.children.length) {
route.redirect = route.path + '/' + route.children[0].path
}
if (level === 2) {
if (level != 1) {
route.component = View
} else {
route.component = Layout
......@@ -49,10 +51,12 @@ function filterAsyncRouter(asyncRouterMap, level) {
}
}
if (route.children != null && route.children && route.children.length) {
route.children = filterAsyncRouter(route.children, 2)
route.children = filterAsyncRouter(route.children)
}
return true
})
level--
return res
}
export const loadView = (view) => {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!