Browse Source

fix[Breadcurmb]: fixed pathCompile bug #217

Pan 6 years ago
parent
commit
2dcd0aa08a
1 changed files with 7 additions and 5 deletions
  1. 7 5
      src/components/Breadcrumb/index.vue

+ 7 - 5
src/components/Breadcrumb/index.vue

@@ -3,7 +3,7 @@
3
     <transition-group name="breadcrumb">
3
     <transition-group name="breadcrumb">
4
       <el-breadcrumb-item v-for="(item,index) in levelList" v-if="item.meta.title" :key="item.path">
4
       <el-breadcrumb-item v-for="(item,index) in levelList" v-if="item.meta.title" :key="item.path">
5
         <span v-if="item.redirect==='noredirect'||index==levelList.length-1" class="no-redirect">{{ item.meta.title }}</span>
5
         <span v-if="item.redirect==='noredirect'||index==levelList.length-1" class="no-redirect">{{ item.meta.title }}</span>
6
-        <router-link v-else :to="item.redirect||item.path">{{ item.meta.title }}</router-link>
6
+        <router-link v-else :to="item.redirect||pathCompile(item.path)">{{ item.meta.title }}</router-link>
7
       </el-breadcrumb-item>
7
       </el-breadcrumb-item>
8
     </transition-group>
8
     </transition-group>
9
   </el-breadcrumb>
9
   </el-breadcrumb>
@@ -28,12 +28,8 @@ export default {
28
   },
28
   },
29
   methods: {
29
   methods: {
30
     getBreadcrumb() {
30
     getBreadcrumb() {
31
-      const { params } = this.$route
32
       let matched = this.$route.matched.filter(item => {
31
       let matched = this.$route.matched.filter(item => {
33
         if (item.name) {
32
         if (item.name) {
34
-          // To solve this problem https://github.com/PanJiaChen/vue-element-admin/issues/561
35
-          var toPath = pathToRegexp.compile(item.path)
36
-          item.path = toPath(params)
37
           return true
33
           return true
38
         }
34
         }
39
       })
35
       })
@@ -42,6 +38,12 @@ export default {
42
         matched = [{ path: '/dashboard', meta: { title: 'Dashboard' }}].concat(matched)
38
         matched = [{ path: '/dashboard', meta: { title: 'Dashboard' }}].concat(matched)
43
       }
39
       }
44
       this.levelList = matched
40
       this.levelList = matched
41
+    },
42
+    pathCompile(path) {
43
+      // To solve this problem https://github.com/PanJiaChen/vue-element-admin/issues/561
44
+      const { params } = this.$route
45
+      var toPath = pathToRegexp.compile(path)
46
+      return toPath(params)
45
     }
47
     }
46
   }
48
   }
47
 }
49
 }