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) {
|
||||
routeToItem(item, error => {
|
||||
activeIndex.value = oldActiveIndex
|
||||
if (error) {
|
||||
// vue-router 3.1.0+ push/replace cause NavigationDuplicated error
|
||||
// https://github.com/ElemeFE/element/issues/17044
|
||||
if (error.name === 'NavigationDuplicated') return
|
||||
console.error(error)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
let route = item.route || item.index
|
||||
router?.push(route)
|
||||
.then(navigationResult => {
|
||||
//vue-router NavigationFailureType duplicated
|
||||
const DUPLICATE_ROUTE = 16
|
||||
if (navigationResult && navigationResult.type !== DUPLICATE_ROUTE) {
|
||||
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