fix(menu): fix el-menu activeIndex bug (#2468)

This commit is contained in:
itreetree 2021-07-13 16:57:05 +08:00 committed by GitHub
parent 0074f334fe
commit 10d24a76ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)
}
}