NavigationDuplicated: Avoided redundant navigation to current location: “/“.

小鱼儿 2022-11-21 01:25 326阅读 0赞

在写导航切换时点击会有以下报错
在这里插入图片描述
这个报错是是路由中点击路径重复 ,也有可能是安装的vue-router还是之前出错的那个版本,在项目目录下运行 npm i vue-router@3.0 -S 即可。
解决方法1:在 main.js里添加一段代码。
代码如下:

  1. import Router from 'vue-router'
  2. const routerPush = Router.prototype.push
  3. Router.prototype.push = function push(location) {
  4. return routerPush.call(this, location).catch(error=> error)}

解决方法2:安装

  1. npm i vue-router@3.0 -S
  2. //npm 安装慢 要是有安装淘宝镜像 cnpm安装也可以

发表评论

表情:
评论列表 (有 0 条评论,326人围观)

还没有评论,来说两句吧...

相关阅读