iView-admin 动态路由问题

iView-admin 动态路由问题

IView-admin 配置动态路由后选项卡不能打开的问题

问题描述:
跳转客户详细后,点击其它页,然后再从选项卡进入页面时,发下控制台 报错,不能正常打开客户详细页面

[vue-router] Route with name 'customer/detail/:id' does not exist

地址栏的地址变为 http://localhost:8080/ 正确的地址为 http://localhost:8080/customer/detail/150
路由器配置如下

{
    path: 'detail/:id',
    name: 'customer/detail',
    meta: {
      title: '客户详细',
      hideInMenu: true
    },
    component: () => import('@/view/customer/detail/detail.vue')
}

最后找到原因是,IView-admin 路由跳转使用的是

turnToPage (name) {
  if (name.indexOf('isTurnByHref_') > -1) {
    window.open(name.split('_')[1])
    return
  }
  this.$router.push({
    name: name
  })
},

采用 this.$router.push({name: name}) 来跳转
在浏览器的Local Storage里发现是这样存储的

turnToPagePath (path) {
  if (name.indexOf('isTurnByHref_') > -1) {
    window.open(name.split('_')[1])
    return
  }
  this.$router.push({
    path: path
  })
},

然后修改 main.vue handleClick 部分代码

handleClick (item) {
  // this.turnToPage(item.name)
  this.turnToPagePath(item.path)
}

问题解决

由此引发了新问题

从列表打开id为150的客户信息,再从列表打开id为140的客户信息。从别的页面点选项卡跳转到客户详细页面 发现还是进入到 150的客户信息,而不是最新 140的客户信息
解决方法,修改 util.js
之前的代码

export const getNewTagList = (list, newRoute) => {
  const { name, path, meta } = newRoute
  let newList = [...list]
  if (newList.findIndex(item => item.name === name) >= 0) return newList
  else newList.push({ name, path, meta })
  return newList
}

修改后的代码

export const getNewTagList = (list, newRoute) => {
  const { name, path, meta } = newRoute
  let newList = [...list]
  let _index = newList.findIndex(item => item.name === name)
  if (_index >= 0) {
    if (newList[_index].path !== path) {    // 如果name已经存在,判断path值
      newList[_index].path = path           // 如果不一样,修改path值
    }
    return newList
  } else newList.push({ name, path, meta })
  return newList
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值