Skip to content

Commit

Permalink
fix: named routes close #55
Browse files Browse the repository at this point in the history
  • Loading branch information
Scrum committed Jun 24, 2019
1 parent ddf9248 commit cd41adc
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/components/breadcrumbs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ export default {
methods: {
getBreadcrumb(bc) {
return typeof bc === 'function' ? bc.call(this, this.$route.params) : bc;
},
getPath(crumb) {
let {path} = crumb;
for (let [key, value] of Object.entries(this.$route.params)) {
path = path.replace(`:${key}`, value);
}
return path;
}
},
template: `
Expand All @@ -15,11 +24,11 @@ export default {
class="breadcrumb-item"
v-if="crumb.meta.breadcrumb"
v-for="(crumb, i) in $breadcrumbs"
:key="crumb"
:key="i"
>
<router-link
active-class="active"
:to="{ path: crumb.path }"
:to="{ path: getPath(crumb) }"
:tag="i != $breadcrumbs.length - 1 ? 'a' : 'span'"
>
{{ getBreadcrumb(crumb.meta.breadcrumb) }}
Expand Down

0 comments on commit cd41adc

Please sign in to comment.