跳转的路由和当前的路由相同的时候就会出现报错,所以需要解决
1、当前路由:/myTodo
this.$router.push({
path: '/myTodo'
})
1-1、报错:
2、解决问题:
import VueRouter from 'vue-router';
// hack router push callback
// [解决 vue-router跳转相同路径报错 ]
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location, onResolve, onReject) {
if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
return originalPush.call(this, location).catch(err => err)
}