Vue-router跳转同一路由报错

276 阅读1分钟

Vue-router跳转同一路由报错

跳转的路由和当前的路由相同的时候就会出现报错,所以需要解决

报错的截图如下

11.png

在router.js文件中添加这一段代码

import Router from 'vue-router'

// 解决跳转同一个路由的报错方法
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}