• 解决 Vue 重复点击相同路由,出现 Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation 问题


    问题描述:重复点击导航时,控制台出现报错 ,虽然不影响功能使用,但也不能视而不见。

    解决方案:

    方案一:重写push方法,只需在 router 文件夹下,添加如下代码:

    // src/router/index.js
    Vue.use(Router)
    const router = new Router({
    routes
    })
    
    const VueRouterPush = Router.prototype.push
    Router.prototype.push = function push (to) {
    return VueRouterPush.call(this, to).catch(err => err)
    }

    方案二:在跳转时,判断是否跳转路由和当前路由是否一致,避免重复跳转产生问题。

    toMenu (item) {
      if (this.$route.path !== item.url) {
        this.$router.push({ path: item.url })
      }
    }

    方案三:使用 catch 方法捕获 router.push 异常。

    this.$router.push(route).catch(err => {
        console.log('输出报错',err)
    })

    原文出处:https://blog.csdn.net/qq_36437172/article/details/108269846

  • 相关阅读:
    java读取excel文件内容
    JavaScript函数写法整理
    Redis命令
    Redis简单入门
    Redis介绍
    NodeJS代码调试
    React组件生命周期
    解决swiper动态改变数据后分页混乱问题
    [LeetCode] 343. Integer Break
    [LeetCode] 304. Range Sum Query 2D
  • 原文地址:https://www.cnblogs.com/jy17/p/16002887.html
Copyright © 2020-2023  润新知