export const routeEqual = (route1, route2) => {
if (!route1 || !route2) {
return true
}
const params1 = route1 && route1.params ? route1.params : {}
const params2 = route2 && route2.params ? route2.params : {}
const query1 = route1 && route1.query ? route1.query : {}
const query2 = route2 && route2.query ? route2.query : {}
// 课程路径,只对比id。目的为了选中topMenu。path 有可能为空,最好能通过route.name获取到path来截取对比
let isCoursePath = false
let path = route1.path || route2.path || window.location.pathname
if (path) {
if (sliceUrl(path, 0, 4).indexOf('training/course') > -1) {
isCoursePath = true
}
if (sliceUrl(path, 0, 4).indexOf('training/responsible-course') > -1) {
isCoursePath = true
}
if (sliceUrl(path, 0, 5).indexOf('maintenance/training/course') > -1) {
isCoursePath = true
}
if (sliceUrl(path, 0, 5).indexOf('audit/auditList/course') > -1) {
isCoursePath = true
}
if (sliceUrl(path, 0, 5).indexOf('examination/examination/home') > -1) {
isCoursePath = true
}
}
if (isCoursePath) {
let uniqueId1 = route1.meta.uniqueId || query1.id
let uniqueId2 = route2.meta.uniqueId || query2.id
// 判断参数一致
let uniqueIdEqual = uniqueId1 && String(uniqueId1) === String(uniqueId2)
// 新增不判断是同一个窗口
let isNotAddNew = !(String(route2.meta.addCourse) === 'true' || String(route1.meta.addCourse) === 'true')
if (isNotAddNew && uniqueIdEqual) {
return true
}
}
let result = route1.name === route2.name && objEqual(params1, params2) && objEqual(query1, query2)
return result
}
在这边加上考试的路径就行了去校验