vue-router.esm.js?8c4f:2065 Uncaught (in promise) NavigationDuplicated: Avoided redundant navigat...

vue-router.esm.js?8c4f:2065 Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: "/cart".

今天在写导航切换页面的时候遇到了这个问题,因为 首页切换按钮本身在App页面上,即路由地址为’ /cart ’ 的页面,重定向到的页面依然是cart页面,也就是所谓的产生了冗余导航,vue-router便报错了。

解决办法 1 :

将如下代码 重写push方法 加入到路由设置文件index.js中即可:

const originalPush = VueRouter.prototype.push

VueRouter.prototype.push = function push(location) {

  return originalPush.call(this, location).catch(err => err)

}

解决办法 2 :

将 重定向 放到 末尾

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容