報(bào)錯(cuò)情況? 點(diǎn)擊跳轉(zhuǎn)路由時(shí),重復(fù)點(diǎn)擊
Avoided redundant navigation to current location: "/".
大致意思: 避免重復(fù)跳轉(zhuǎn)至同一個(gè)路由"/"
查資料發(fā)現(xiàn)解決的辦法有兩種:
1.vue-router版本高了,會(huì)報(bào)這個(gè)錯(cuò)誤,可以裝低版本的路由,例如vue-router@3.0
2.就是我下面的解決辦法,在router的index.ts中重寫(xiě)push方法,拋出錯(cuò)誤即可,用replace寫(xiě)的跳轉(zhuǎn)就重寫(xiě)replace方法就行。
//解決重復(fù)路由跳轉(zhuǎn)報(bào)錯(cuò)
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
? ? return (originalPush.call(this, location) as any).catch(err => err)
}