如何解決iView-admin動(dòng)態(tài)路由問(wèn)題-創(chuàng)新互聯(lián)

這篇文章將為大家詳細(xì)講解有關(guān)如何解決iView-admin動(dòng)態(tài)路由問(wèn)題,小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

創(chuàng)新互聯(lián)為客戶提供專業(yè)的網(wǎng)站設(shè)計(jì)制作、成都網(wǎng)站建設(shè)、程序、域名、空間一條龍服務(wù),提供基于WEB的系統(tǒng)開(kāi)發(fā). 服務(wù)項(xiàng)目涵蓋了網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站程序開(kāi)發(fā)、WEB系統(tǒng)開(kāi)發(fā)、微信二次開(kāi)發(fā)、手機(jī)網(wǎng)站制作設(shè)計(jì)等網(wǎng)站方面業(yè)務(wù)。

 IView-admin 在使用的時(shí)候

跳轉(zhuǎn)客戶詳細(xì)后,點(diǎn)擊其它頁(yè)面,然后再?gòu)倪x項(xiàng)卡進(jìn)入頁(yè)面時(shí),發(fā)下控制臺(tái) 報(bào)錯(cuò),不能正常打開(kāi)客戶詳細(xì)頁(yè)面

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

地址欄的地址變?yōu)?http://localhost:8080/  正確的地址為 http://localhost:8080/customer/detail/150

路由器配置如下

{

  path: 'detail/:id',

  name: 'customer/detail',

  meta: {

   title: '客戶詳細(xì)',

   hideInMenu: true

  },

  component: () => import('@/view/customer/detail/detail.vue')

}

最后找到原因是,IView-admin 路由跳轉(zhuǎn)使用的是

turnToPage (name) {

 if (name.indexOf('isTurnByHref_') > -1) {

  window.open(name.split('_')[1])

  return

 }

 this.$router.push({

  name: name

 })
},

采用 this.$router.push({name: name}) 來(lái)跳轉(zhuǎn)

在瀏覽器的Local Storage里發(fā)現(xiàn)是這樣存儲(chǔ)的

{"name":"customer/detail","path":"/customer/detail/150","meta":{"title":"客戶詳細(xì)","hideInMenu":true}}

name 上邊沒(méi)有客戶詳細(xì)的ID信息,所以跳轉(zhuǎn)的時(shí)候出現(xiàn)了問(wèn)題。

現(xiàn)將 mian.vue truenToPage 下新增代碼,采用this.$router.push({path: path})方式來(lái)跳轉(zhuǎn)

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)

}

問(wèn)題解決

由此引發(fā)了新問(wèn)題

從列表打開(kāi)id為150的客戶信息,再?gòu)牧斜泶蜷_(kāi)id為140的客戶信息。從別的頁(yè)面點(diǎn)選項(xiàng)卡跳轉(zhuǎn)到客戶詳細(xì)頁(yè)面 發(fā)現(xiàn)還是進(jìn)入到 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已經(jīng)存在,判斷path值

   newList[_index].path = path      // 如果不一樣,修改path值

  }

  return newList

 } else newList.push({ name, path, meta })

 return newList

}

關(guān)于“如何解決iView-admin動(dòng)態(tài)路由問(wèn)題”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。

新聞名稱:如何解決iView-admin動(dòng)態(tài)路由問(wèn)題-創(chuàng)新互聯(lián)
文章位置:http://www.muchs.cn/article32/djjjsc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站排名商城網(wǎng)站、外貿(mào)建站、網(wǎng)站建設(shè)、網(wǎng)站導(dǎo)航、做網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

搜索引擎優(yōu)化