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: } ] })
Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: