Skip to content

Commit

Permalink
fix: incorrect resolve multi parents, close #105
Browse files Browse the repository at this point in the history
  • Loading branch information
Scrum committed Oct 12, 2020
1 parent 2c29db1 commit ca1831d
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,22 @@ class VueBreadcrumbs implements PluginObject<ComponentOptions<Vue>> {
options.render = undefined;
}


Object.defineProperties(Vue.prototype, {
$breadcrumbs: {
get(): RouteRecord[] {
function findParents(this: Vue, routeName: string, matches: RouteRecord[] = []): RouteRecord[] {
const [routeParent]: RouteRecord[] = this.$router.resolve({ name: routeName }).route.matched;
matches.unshift(routeParent);
const parentName: string = routeParent.meta?.breadcrumb?.parent;

if (parentName) {
return findParents.call(this, routeParent.meta.breadcrumb.parent, matches);
}

return matches;
}

return this.$route.matched
.flatMap((route: RouteRecord) => {
let routeRecord: RouteRecord[] = [route];
Expand All @@ -30,8 +43,7 @@ class VueBreadcrumbs implements PluginObject<ComponentOptions<Vue>> {
}

if (breadcrumb?.parent) {
const matched = this.$router.resolve({ name: breadcrumb.parent }).route.matched

const matched = findParents.call(this, breadcrumb.parent, []);
routeRecord = [...matched, ...routeRecord];
}

Expand Down

0 comments on commit ca1831d

Please sign in to comment.