Skip to content

Commit d828207

Browse files
committed
fix(material-angular-io): sidenav links not updating
Fixes that the links in the docs sidenav weren't updating on navigation and avoids passing route parameters around.
1 parent ee5b13f commit d828207

File tree

3 files changed

+9
-16
lines changed

3 files changed

+9
-16
lines changed

material.angular.io/src/app/pages/component-sidenav/component-nav.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<div class="docs-component-viewer-nav">
22
@let items = (this.items | async) || [];
3+
@let params = this._params | async;
34

45
@if (items.length > 0) {
56
<div class="docs-component-viewer-nav-content">
67
<mat-nav-list>
78
@for (component of items; track component) {
89
<a mat-list-item #link="routerLinkActive"
9-
[routerLink]="'/' + params()?.section + '/' + component.id"
10+
[routerLink]="'/' + params?.section + '/' + component.id"
1011
[activated]="link.isActive"
1112
routerLinkActive="docs-component-viewer-sidenav-item-selected"
1213
[attr.aria-current]="link.isActive ? 'page': 'false'">

material.angular.io/src/app/pages/component-sidenav/component-sidenav.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[mode]="(isScreenSmall | async) ? 'over' : 'side'"
77
[fixedInViewport]="(isScreenSmall | async)"
88
[fixedTopGap]="(isExtraScreenSmall | async) ? 92 : 56">
9-
<app-component-nav [params]="params | async"></app-component-nav>
9+
<app-component-nav/>
1010
</mat-sidenav>
1111
}
1212
<div class="docs-component-sidenav-content">
@@ -15,7 +15,7 @@
1515
<main class="docs-component-sidenav-body-content">
1616
<!-- If on large screen, menu resides to left of content -->
1717
@if ((isScreenSmall | async) === false) {
18-
<app-component-nav [params]="params | async"/>
18+
<app-component-nav/>
1919
}
2020
<router-outlet></router-outlet>
2121
</main>

material.angular.io/src/app/pages/component-sidenav/component-sidenav.ts

+5-13
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
RouterLinkActive,
2222
RouterLink,
2323
} from '@angular/router';
24-
import {combineLatest, Observable, Subscription} from 'rxjs';
24+
import {Observable, of, Subscription} from 'rxjs';
2525
import {map, switchMap} from 'rxjs/operators';
2626

2727
import {DocumentationItems} from '../../shared/documentation-items/documentation-items';
@@ -66,11 +66,9 @@ const SMALL_WIDTH_BREAKPOINT = 959;
6666
})
6767
export class ComponentSidenav implements OnInit, OnDestroy {
6868
docItems = inject(DocumentationItems);
69-
private _route = inject(ActivatedRoute);
7069
private _navigationFocusService = inject(NavigationFocusService);
7170

7271
readonly sidenav = viewChild(MatSidenav);
73-
params: Observable<Params>;
7472
isExtraScreenSmall: Observable<boolean>;
7573
isScreenSmall: Observable<boolean>;
7674
private _subscriptions = new Subscription();
@@ -84,11 +82,6 @@ export class ComponentSidenav implements OnInit, OnDestroy {
8482
this.isScreenSmall = breakpoints
8583
.observe(`(max-width: ${SMALL_WIDTH_BREAKPOINT}px)`)
8684
.pipe(map(breakpoint => breakpoint.matches));
87-
88-
this.params = combineLatest(
89-
this._route.pathFromRoot.map(route => route.params),
90-
Object.assign,
91-
);
9285
}
9386

9487
ngOnInit() {
@@ -120,12 +113,11 @@ export class ComponentSidenav implements OnInit, OnDestroy {
120113
})
121114
export class ComponentNav {
122115
private _docItems = inject(DocumentationItems);
123-
readonly params = input<Params | null>();
116+
private _route = inject(ActivatedRoute);
117+
protected _params = this._route.params;
124118

125-
items = toObservable(this.params).pipe(
126-
switchMap(params =>
127-
params?.section ? this._docItems.getItems(params.section) : Promise.resolve(null),
128-
),
119+
items = this._params.pipe(
120+
switchMap(params => (params?.section ? this._docItems.getItems(params.section) : of([]))),
129121
);
130122
}
131123

0 commit comments

Comments
 (0)