|
@@ -103,11 +103,23 @@ const permission = {
|
|
|
const ancestors = { fullMatched: false, matches: [] }
|
|
|
let targetPath = to.path
|
|
|
traceAncestorRoutesInMenus(topRoutes, targetPath, ancestors)
|
|
|
+ // try to fix active menus by parentPath config
|
|
|
if (!ancestors.fullMatched && to.meta?.parentPath) {
|
|
|
targetPath = to.meta.parentPath
|
|
|
ancestors.matches.length = 0 // clear for re-trace
|
|
|
traceAncestorRoutesInMenus(topRoutes, targetPath, ancestors)
|
|
|
}
|
|
|
+ // try to fix active menus by parentRoute config.
|
|
|
+ // only match exactly routeName, so active menus will not be changed when config is wrong.
|
|
|
+ if (!ancestors.fullMatched && to.meta?.parentRoute) {
|
|
|
+ const parentTo = { name: to.meta.parentRoute }
|
|
|
+ const matched = router.getMatchedComponents(parentTo)
|
|
|
+ if (matched.length) {
|
|
|
+ targetPath = router.resolve(parentTo).href
|
|
|
+ ancestors.matches.length = 0 // clear for re-trace
|
|
|
+ traceAncestorRoutesInMenus(topRoutes, targetPath, ancestors)
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
// 完全匹配,开始操作菜单
|
|
|
if (ancestors.fullMatched) {
|
|
@@ -223,7 +235,7 @@ function handleAsyncRouterComponent(route) {
|
|
|
|
|
|
function handleAsyncRouterLocalReference(route, parent, level) {
|
|
|
// 属性挂在meta上可以不受匹配方法等因素的影响,最大限度保留设置
|
|
|
- route.meta = route.meta || {}
|
|
|
+ route.meta = route.meta || { routeName: null }
|
|
|
route.name = route.meta.routeName || route.name // overwrite route name by server meta config
|
|
|
// 挂parent可逆向追溯, 不能挂反向引用vuex内部会深拷贝!
|
|
|
// route.parent = parent
|