美文网首页
Vue router name 重名导致的异常

Vue router name 重名导致的异常

作者: 码字与律动 | 来源:发表于2020-09-25 17:42 被阅读0次

项目中遇到的问题是,如果没有设置next(newTo),那么项目菜单栏切换是没有问题的,如果设置了,就会出现错乱,现在知道原因是router里name重名导致的异常,但是具体为什么,还不是很明白,这里就当时记录一下。

router.beforeEach((to, from, next) => {
  console.log('---to---', to)
  // console.log('---next', next)
  if (!to.meta.hello) {
    to.meta.hello = true
    let newTo = {...to}
    newTo.query.version = window.afterFix || 'v11111111'
    next(newTo)
  }
  if (0 || localStorage.getItem('userData')) {
    console.log('---to---2222', to)
    next()
  } else {
    if (to.path === '/Login') {
      next()
    } else {
      next({
        path: '/Login'
      })
    }
  }
})

相关文章

网友评论

      本文标题:Vue router name 重名导致的异常

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