mirror of
https://github.com/element-plus/element-plus.git
synced 2024-12-27 03:01:14 +08:00
fix(menu): fix el-menu activeIndex bug (#2468)
This commit is contained in:
parent
0074f334fe
commit
10d24a76ab
@ -205,24 +205,21 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (props.router && router && hasIndex) {
|
if (props.router && router && hasIndex) {
|
||||||
routeToItem(item, error => {
|
let route = item.route || item.index
|
||||||
activeIndex.value = oldActiveIndex
|
router?.push(route)
|
||||||
if (error) {
|
.then(navigationResult => {
|
||||||
// vue-router 3.1.0+ push/replace cause NavigationDuplicated error
|
//vue-router NavigationFailureType duplicated
|
||||||
// https://github.com/ElemeFE/element/issues/17044
|
const DUPLICATE_ROUTE = 16
|
||||||
if (error.name === 'NavigationDuplicated') return
|
if (navigationResult && navigationResult.type !== DUPLICATE_ROUTE) {
|
||||||
console.error(error)
|
activeIndex.value = oldActiveIndex
|
||||||
}
|
throw navigationResult
|
||||||
})
|
}
|
||||||
}
|
})
|
||||||
}
|
.catch(error => {
|
||||||
|
activeIndex.value = oldActiveIndex
|
||||||
|
throw error
|
||||||
|
})
|
||||||
|
|
||||||
const routeToItem = (item, onError) => {
|
|
||||||
let route = item.route || item.index
|
|
||||||
try {
|
|
||||||
router?.push(route, () => null, onError)
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user