溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

如何解決iView-admin動態(tài)路由問題

發(fā)布時間:2021-07-21 10:15:25 來源:億速云 閱讀:117 作者:小新 欄目:web開發(fā)

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

 IView-admin 在使用的時候

跳轉(zhuǎn)客戶詳細后,點擊其它頁面,然后再從選項卡進入頁面時,發(fā)下控制臺 報錯,不能正常打開客戶詳細頁面

[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: '客戶詳細',

   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}) 來跳轉(zhuǎn)

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

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

name 上邊沒有客戶詳細的ID信息,所以跳轉(zhuǎn)的時候出現(xiàn)了問題。

現(xiàn)將 mian.vue truenToPage 下新增代碼,采用this.$router.push({path: path})方式來跳轉(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)

}

問題解決

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

從列表打開id為150的客戶信息,再從列表打開id為140的客戶信息。從別的頁面點選項卡跳轉(zhuǎn)到客戶詳細頁面 發(fā)現(xià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

}

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

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI