雖然此報錯並不會影響項目運行,但是作為一個強迫症的碼農的確受不了error,解決方法如下:
方法1:在項目目錄下運行 npm i vue-router@3.0 -S 將vue-router改為3.0版本即可;
方法2:若不想更換版本解決方法:
在router.js中加入以下代碼就可以
記住插入的位置
const originalPush = Router.prototype.push Router.prototype.push = function push(location) { return originalPush.call(this, location).catch(err => err) }
// 如果你的改了push還是沒有生效,可以考慮改replace方法
// 修改路由replace方法,阻止重復點擊報錯
const originalReplace = VueRouter.prototype.replace; VueRouter.prototype.replace = function replace(location) { return originalReplace.call(this, location).catch(err => err); };