Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug Report] 升级vue-router至3.1以后版本,导航组件重复点击报错 NavigationDuplicated #17044

Closed
xinde opened this issue Aug 15, 2019 · 8 comments · Fixed by #17269

Comments

@xinde
Copy link

xinde commented Aug 15, 2019

Element UI version

2.11.1

OS/Browsers version

Win/chrome

Vue version

2.6.10

Reproduction Link

vuejs/vue-router#2881

Steps to reproduce

升级vue-router至新版本后,使用 el-menu 来导航页面,重复点击某一个导航项就会在控制台报错,vue-router官方给出了一些修改方法,element这边是不是要同步修改

What is Expected?

不报错 NavigationDuplicated

What is actually happening?

控制台 NavigationDuplicated

@element-bot element-bot changed the title [Bug Report] 升级vue-router至3.1以后版本,导航组件重复点击报错 [Bug Report] Upgraded vue-router to version 3.1 and later, navigation component repeated clicks to report errors Aug 15, 2019
@element-bot
Copy link
Member

Translation of this issue:

Element UI version

2.11.1

OS/Browsers version

Win/chrome

Vue version

2.6.10

Reproduction Link

Https://github.com/vuejs/vue-router/issues/2881

Steps to reproduce

Upgrading vue-router to the new version, using el-menu to navigate the page, repeated clicks on a navigation item will report an error in the console, vue-router official gave some modification methods, elementary side is not to be synchronized modification

What is Expected?

Error-free Navigation Duplicated

What is actually happening?

Console Navigation Duplicated

@xinde xinde changed the title [Bug Report] Upgraded vue-router to version 3.1 and later, navigation component repeated clicks to report errors [Bug Report] 升级vue-router至3.1以后版本,导航组件重复点击报错 NavigationDuplicated Aug 15, 2019
@paina-ma
Copy link

请问解决了吗?

@xinde
Copy link
Author

xinde commented Aug 22, 2019

请问解决了吗?

没有,回退了vue-router版本,暂时用着

官方的解释:
vuejs/vue-router#2881 (comment)

@gongshun
Copy link

先卸载vue-router,再安装3.0.7版本可以解决。
npm uninstall vue-router
npm install [email protected]

@paina-ma
Copy link

paina-ma commented Aug 22, 2019 via email

@paina-ma
Copy link

paina-ma commented Aug 23, 2019 via email

@liyuec
Copy link

liyuec commented May 10, 2021

image

Uncaught (in promise) Error: Redirected when going from "????" to "????" via a navigation guard.

router 3.5.0+ 会有这个问题,在不降低版本的情况下,不修改发布elementUI 也能解决。具体原因参加router源码hooks部分的 to 验证
前提:
【1】不降低router版本
【2】不构建与发布私有elementUI
【3】不修改vue-router ,只针对单个项目固定版本的elementUI

### 解决:

在main.js里

 import {
  Menu
} from 'element-ui';

重写 Menu的 handleItemClick 方法 , 具体代码如下,至于想如何处理,看自己系统业务,这里只提供基础的解决办法。

Menu.methods.handleItemClick = function handleItemClick(item) {
  var _this = this;

  var index = item.index,
      indexPath = item.indexPath;

  var oldActiveIndex = this.activeIndex;
  var hasIndex = item.index !== null;

  if (hasIndex) {
    this.activeIndex = item.index;
  }

  this.$emit('select', index, indexPath, item);

  if (this.mode === 'horizontal' || this.collapse) {
    this.openedMenus = [];
  }

  if (this.router && hasIndex) {
    this.routeToItem(item, function (error) {
      _this.activeIndex = oldActiveIndex;
      if (error) {
        // vue-router 3.1.0+ push/replace cause NavigationDuplicated error 
        // https://github.com/ElemeFE/element/issues/17044
        if (error.name === 'NavigationDuplicated') return;
        if(error.message){
          if(error.message.indexOf('when going') < 0){
            console.error(error);
          }
        }
        console.log('my Menu.methods.handleItemClick')
      }
    });
  }
}

@imaverickk
Copy link

imaverickk commented Jul 27, 2021

vue-router 3.5.2
点击的导航被全局beforeEach重定向到相同路径(业务需要修改query)后仍会出现这个错误
断点后发现error没有name属性,因为不是NavigationDuplicated错误

QQ截图20210727195333

https://github.com/vuejs/vue-router/blob/v3.5.2/src/util/errors.js
目前只忽略了duplicated错误,redirected通常也是预期行为,是不是也忽略掉会更好?

vue-router新增了isNavigationFailure方法来判断错误类型

import VueRouter from 'vue-router'
const { isNavigationFailure, NavigationFailureType } = VueRouter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants