Skip to content

Commit d1cceb6

Browse files
authored
feature: add pathToRegexp to compile path (PanJiaChen#1148)
1 parent ff13ee1 commit d1cceb6

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
"node-sass": "^4.7.2",
9595
"optimize-css-assets-webpack-plugin": "5.0.0",
9696
"ora": "3.0.0",
97+
"path-to-regexp": "2.4.0",
9798
"portfinder": "1.0.13",
9899
"postcss-import": "11.1.0",
99100
"postcss-loader": "2.1.6",

src/components/Breadcrumb/index.vue

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
<script>
1313
import { generateTitle } from '@/utils/i18n'
14+
import pathToRegexp from 'path-to-regexp'
1415
1516
export default {
1617
data() {
@@ -29,7 +30,15 @@ export default {
2930
methods: {
3031
generateTitle,
3132
getBreadcrumb() {
32-
let matched = this.$route.matched.filter(item => item.name)
33+
const { params } = this.$route
34+
let matched = this.$route.matched.filter(item => {
35+
if (item.name) {
36+
// To solve this problem https://github.com/PanJiaChen/vue-element-admin/issues/561
37+
var toPath = pathToRegexp.compile(item.path)
38+
item.path = toPath(params)
39+
return true
40+
}
41+
})
3342
const first = matched[0]
3443
if (first && first.name.trim().toLocaleLowerCase() !== 'Dashboard'.toLocaleLowerCase()) {
3544
matched = [{ path: '/dashboard', meta: { title: 'dashboard' }}].concat(matched)

0 commit comments

Comments
 (0)