1. 程式人生 > 其它 >Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location:

Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location:

Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: “/users”. 關於這個報錯的原因和解決方案如下:

原因: 原始碼 install 安裝依賴時,Router(路由版本不一致) 也可以修改 package.json 裡面的 Router 版本

解決方案:在router資料夾下的index.js中加入如下程式碼

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

index.js中完整的程式碼如下:

import Vue from 'vue'
import Router from 'vue-router'
import Index from "../components/Index";
import List from "../components/users/List";

Vue.use(Router)
const originalPush = Router.prototype.push
Router.prototype.push 
= function push(location) { return originalPush.call(this, location).catch(err => err) } export default new Router({ routes: [ {path: '/', redirect:'/index'}, {path:'/index', name:Index, component:Index},/*這裡的ecomponent後便容易多一個s*/ {path: '/users', component: List}, // {path: '',component: }
] })