Skip to content

Commit

Permalink
Simplify code detecting a navigation to the default route
Browse files Browse the repository at this point in the history
  • Loading branch information
abelgomez committed Jul 4, 2024
1 parent 6a1bb9b commit dac445a
Showing 1 changed file with 4 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,14 @@ export class ComcolPageBrowseByComponent implements OnDestroy, OnInit {
),
]).subscribe(([navOptions, url]: [ComColPageNavOption[], string]) => {
for (const option of navOptions) {
if (option.routerLink === url?.split('?')[0]) {
if (url?.split('?')[0].endsWith(`/${this.id}`)) {
const option = navOptions.find(o => o.id === this.appConfig[this.contentType].defaultBrowseTab);

Check failure on line 149 in src/app/shared/comcol/comcol-page-browse-by/comcol-page-browse-by.component.ts

View workflow job for this annotation

GitHub Actions / tests (20.x)

'option' is already declared in the upper scope on line 147 column 18
void this.router.navigate([option.routerLink], { queryParams: option.params });
} else if (option.routerLink === url?.split('?')[0]) {
this.currentOption$.next(option);
}
}
}));

this.allOptions$.pipe(
take(1),
).subscribe((allOptions: ComColPageNavOption[]) => {
if (!allOptions.find(o => o.routerLink === this.router.url?.split('?')[0])) {
const option = allOptions.find(o => o.id === this.appConfig[this.contentType].defaultBrowseTab);
void this.router.navigate([option.routerLink], { queryParams: option.params });
}
});
}

ngOnDestroy(): void {
Expand Down

0 comments on commit dac445a

Please sign in to comment.