美文网首页
Vue Router 使用$router.push跳转到一个相同

Vue Router 使用$router.push跳转到一个相同

作者: Cherry丶小丸子 | 来源:发表于2021-06-08 16:30 被阅读0次

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

vue router.png

解决方案

`在路由的配置文件(index.js)中,导入 VueRouter 的时候,进行全局的处理`

import Vue from 'vue'
import VueRouter from 'vue-router'

// 获取原型对象上的push函数
const originalPush = VueRouter.prototype.push;
// 修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter)

相关文章

网友评论

      本文标题:Vue Router 使用$router.push跳转到一个相同

      本文链接:https://www.haomeiwen.com/subject/jqjxeltx.html