Skip to content

Commit

Permalink
fixes #36
Browse files Browse the repository at this point in the history
  • Loading branch information
udayvunnam committed Jul 19, 2020
1 parent d52eb4c commit 0877167
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
8 changes: 4 additions & 4 deletions libs/xng-breadcrumb/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xng-breadcrumb",
"version": "0.0.1",
"version": "5.1.0",
"license": "MIT",
"description": "A declarative and reactive breadcrumb approach for Angular 6 and beyond https://www.npmjs.com/package/xng-breadcrumb",
"author": {
Expand All @@ -24,9 +24,9 @@
"ngx"
],
"peerDependencies": {
"@angular/core": ">=8.0.0",
"@angular/router": ">=8.0.0",
"@angular/common": ">=8.0.0",
"@angular/core": ">=9.0.0",
"@angular/router": ">=9.0.0",
"@angular/common": ">=9.0.0",
"tslib": "^1.10.0",
"rxjs": "*"
}
Expand Down
28 changes: 19 additions & 9 deletions libs/xng-breadcrumb/src/lib/breadcrumb.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export class BreadcrumbService {
private setBaseBreadcrumb() {
const baseConfig = this.router.config.find(pathConfig => pathConfig.path === '');
if (baseConfig && baseConfig.data) {
// tslint:disable-next-line: prefer-const
let { label, alias, skip = false, info, disable = false } = this.getBreadcrumbOptions(baseConfig.data);

let isAutoGeneratedLabel = false;
Expand Down Expand Up @@ -130,6 +131,9 @@ export class BreadcrumbService {
} else if (activatedRoute.firstChild) {
return this.prepareBreadcrumbList(activatedRoute.firstChild, routeLinkPrefix);
}
const lastCrumb = this.currentBreadcrumbs[this.currentBreadcrumbs.length - 1];
this.resolveQueryParamForLastItem(lastCrumb, activatedRoute);

// remove breadcrumb items that needs to be hidden or don't have a label
const breadcrumbsToShow = this.currentBreadcrumbs.filter(item => !item.skip);

Expand All @@ -143,6 +147,7 @@ export class BreadcrumbService {
const resolvedPath = this.resolvePathParam(path, activatedRoute);
const routeLink = `${routeLinkPrefix}${resolvedPath}`;

// tslint:disable-next-line: prefer-const
let { label, alias, skip, disable, info } = this.getFromStore(breadcrumb.alias, routeLink);
let isAutoGeneratedLabel = false;

Expand All @@ -163,7 +168,7 @@ export class BreadcrumbService {
info: info || breadcrumb.info,
routeLink,
isAutoGeneratedLabel,
...this.resolveQueryParam(routeLink, activatedRoute)
...this.resolveQueryParam(routeLink)
};
}

Expand Down Expand Up @@ -283,16 +288,21 @@ export class BreadcrumbService {
return path;
}

private resolveQueryParam(routeLink: string, activatedRoute: ActivatedRoute) {
private resolveQueryParam(routeLink: string): Breadcrumb {
const previousBreadcrumb = this.previousBreadcrumbs.find(item => item.routeLink === routeLink) || {};
const { queryParams, fragment } = activatedRoute.snapshot;

return {
queryParams: Object.keys(queryParams).length > 0 ? { ...queryParams } : previousBreadcrumb.queryParams,
fragment: fragment || previousBreadcrumb.fragment
queryParams: previousBreadcrumb.queryParams,
fragment: previousBreadcrumb.fragment
};
}

private resolveQueryParamForLastItem(lastItem: Breadcrumb, activatedRoute: ActivatedRoute) {
const { queryParams, fragment } = activatedRoute.snapshot;
// For last item in the crumbs set queryParams from activatedRoute
lastItem.queryParams = Object.keys(queryParams).length > 0 ? { ...queryParams } : undefined
lastItem.fragment = fragment
}

/**
* get empty children of a module or Component. Empty child is the one with path: ''
* When parent and it's children (that has empty route path) define data
Expand All @@ -314,9 +324,9 @@ export class BreadcrumbService {

return baseChild && baseChild.data
? this.mergeWithBaseChildData(baseChild, {
...this.getBreadcrumbOptions(data),
...this.getBreadcrumbOptions(baseChild.data)
})
...this.getBreadcrumbOptions(data),
...this.getBreadcrumbOptions(baseChild.data)
})
: this.getBreadcrumbOptions(data);
}

Expand Down

0 comments on commit 0877167

Please sign in to comment.