在vue項目中遇到的小問題,問題描述:跳轉到與當前頁面相同的路由時報錯。例如,當前頁面路徑為/admin/home,觸發點擊事件跳轉路由為/admin/home時會報錯,如下:
報錯信息.png
解決:在router文件下的index.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)
}
Vue.use(Router)