feature: add pathToRegexp to compile path

This commit is contained in:
Pan 2018-10-08 17:28:25 +08:00
parent 691c526458
commit 8c0668d0d3
2 changed files with 12 additions and 1 deletions

View File

@ -50,6 +50,7 @@
"node-sass": "^4.7.2", "node-sass": "^4.7.2",
"optimize-css-assets-webpack-plugin": "5.0.0", "optimize-css-assets-webpack-plugin": "5.0.0",
"ora": "3.0.0", "ora": "3.0.0",
"path-to-regexp": "2.4.0",
"portfinder": "1.0.16", "portfinder": "1.0.16",
"postcss-import": "12.0.0", "postcss-import": "12.0.0",
"postcss-loader": "2.1.6", "postcss-loader": "2.1.6",

View File

@ -10,6 +10,8 @@
</template> </template>
<script> <script>
import pathToRegexp from 'path-to-regexp'
export default { export default {
data() { data() {
return { return {
@ -26,7 +28,15 @@ export default {
}, },
methods: { methods: {
getBreadcrumb() { getBreadcrumb() {
let matched = this.$route.matched.filter(item => item.name) const { params } = this.$route
let matched = this.$route.matched.filter(item => {
if (item.name) {
// To solve this problem https://github.com/PanJiaChen/vue-element-admin/issues/561
var toPath = pathToRegexp.compile(item.path)
item.path = toPath(params)
return true
}
})
const first = matched[0] const first = matched[0]
if (first && first.name !== 'dashboard') { if (first && first.name !== 'dashboard') {
matched = [{ path: '/dashboard', meta: { title: 'Dashboard' }}].concat(matched) matched = [{ path: '/dashboard', meta: { title: 'Dashboard' }}].concat(matched)