当前位置: 移动技术网 > IT编程>脚本编程>vue.js > iView-admin 动态路由问题的解决方法

iView-admin 动态路由问题的解决方法

2018年11月04日  | 移动技术网IT编程  | 我要评论

十一北京天气,张宝胜玩过的女人,三金医药招商网

 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里发现是这样存储的

{"name":"customer/detail","path":"/customer/detail/150","meta":{"title":"客户详细","hideinmenu":true}} 

name 上边没有客户详细的id信息,所以跳转的时候出现了问题。

现将 mian.vue truentopage 下新增代码,采用this.$router.push({path: path})方式来跳转

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

} 

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对移动技术网的支持。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网