Skip to content

Commit

Permalink
fix: enabledNonBlocking strategy for routes (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
udayvunnam authored Jan 3, 2022
1 parent b904dc5 commit 275bd27
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
7 changes: 6 additions & 1 deletion apps/demo/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ const routes: Routes = [
];

@NgModule({
imports: [RouterModule.forRoot(routes, { relativeLinkResolution: 'legacy' })],
imports: [
RouterModule.forRoot(routes, {
relativeLinkResolution: 'legacy',
initialNavigation: 'enabledBlocking',
}),
],
exports: [RouterModule],
})
export class AppRoutingModule {}
8 changes: 4 additions & 4 deletions libs/xng-breadcrumb/src/lib/breadcrumb.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ export class BreadcrumbService {
private detectRouteChanges() {
// Special case where breadcrumb service & component instantiates after a route is navigated.
// Ex: put breadcrumbs within *ngIf and this.router.events would be empty
if (this.router.navigated) {
this.setupBreadcrumbs(this.activatedRoute.snapshot);
}
// This check is also required where { initialNavigation: 'enabledBlocking' } is applied to routes
this.setupBreadcrumbs(this.activatedRoute.snapshot);

this.router.events
.pipe(filter((event) => event instanceof GuardsCheckEnd))
.subscribe((event) => {
// activatedRoute doesn't carry data when shouldReuseRoute returns false
// use the event data with RoutesRecognized as workaround
// use the event data with GuardsCheckEnd as workaround
// Check for shouldActivate in case where the authGuard returns false the breadcrumbs shouldn't be changed
if (event instanceof GuardsCheckEnd && event.shouldActivate) {
this.setupBreadcrumbs(event.state.root);
}
Expand Down
4 changes: 0 additions & 4 deletions todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,3 @@ Why 4+ items? this limit just “feels” right. 🙃
2. Put the ellipses as close to the first item as possible — Items that are closer to the final item (current page) hold more weight to the user so you want to make those items visible.
3. Do not make the ellipses the actual first item — It is beneficial for users to know the origin of the current page they are on, especially if they are taken directly to the page they are on via a link.
4. Upon refreshing / re-navigating to the page, breadcrumbs should be collapsed again — There is no clean way to manually collapse breadcrumbs (nor do I think it is worth the effort) so make sure it is collapsed by default, even if they were expanded before.

## provide documentation via gitbook

[gitbook](https://app.gitbook.com/@udayvunnam/s/angular/)

0 comments on commit 275bd27

Please sign in to comment.