解决vue跳转同一路由报错问题

vue中,如果跳转同一个页面路由,虽不会影响功能,但是会报错

原因:路由的push会向历史记录栈中添加一个记录,同时跳转同一个路由页面,会造成一个重复的添加,导致页面的报错

解决方案:在router的index.js中重写vue的路由跳转push

const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
	return originalPush.call(this, location).catch(err => err);
}

猜你喜欢

转载自blog.csdn.net/hjdjhh/article/details/122806218
今日推荐