Skip to content

Commit e2ffd95

Browse files
authored
fix(material-angular-io): sidenav links not updating (#30564)
Fixes that the links in the docs sidenav weren't updating on navigation and avoids passing route parameters around.
1 parent 9bc810c commit e2ffd95

File tree

3 files changed

+10
-26
lines changed

3 files changed

+10
-26
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

+6-23
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,14 @@ import {
55
ViewEncapsulation,
66
forwardRef,
77
inject,
8-
input,
98
viewChild,
109
} from '@angular/core';
11-
import {toObservable} from '@angular/core/rxjs-interop';
1210
import {BreakpointObserver} from '@angular/cdk/layout';
1311
import {AsyncPipe} from '@angular/common';
1412
import {MatListItem, MatNavList} from '@angular/material/list';
1513
import {MatSidenav, MatSidenavContainer} from '@angular/material/sidenav';
16-
import {
17-
ActivatedRoute,
18-
Params,
19-
Routes,
20-
RouterOutlet,
21-
RouterLinkActive,
22-
RouterLink,
23-
} from '@angular/router';
24-
import {combineLatest, Observable, Subscription} from 'rxjs';
14+
import {ActivatedRoute, Routes, RouterOutlet, RouterLinkActive, RouterLink} from '@angular/router';
15+
import {Observable, of, Subscription} from 'rxjs';
2516
import {map, switchMap} from 'rxjs/operators';
2617

2718
import {DocumentationItems} from '../../shared/documentation-items/documentation-items';
@@ -66,11 +57,9 @@ const SMALL_WIDTH_BREAKPOINT = 959;
6657
})
6758
export class ComponentSidenav implements OnInit, OnDestroy {
6859
docItems = inject(DocumentationItems);
69-
private _route = inject(ActivatedRoute);
7060
private _navigationFocusService = inject(NavigationFocusService);
7161

7262
readonly sidenav = viewChild(MatSidenav);
73-
params: Observable<Params>;
7463
isExtraScreenSmall: Observable<boolean>;
7564
isScreenSmall: Observable<boolean>;
7665
private _subscriptions = new Subscription();
@@ -84,11 +73,6 @@ export class ComponentSidenav implements OnInit, OnDestroy {
8473
this.isScreenSmall = breakpoints
8574
.observe(`(max-width: ${SMALL_WIDTH_BREAKPOINT}px)`)
8675
.pipe(map(breakpoint => breakpoint.matches));
87-
88-
this.params = combineLatest(
89-
this._route.pathFromRoot.map(route => route.params),
90-
Object.assign,
91-
);
9276
}
9377

9478
ngOnInit() {
@@ -120,12 +104,11 @@ export class ComponentSidenav implements OnInit, OnDestroy {
120104
})
121105
export class ComponentNav {
122106
private _docItems = inject(DocumentationItems);
123-
readonly params = input<Params | null>();
107+
private _route = inject(ActivatedRoute);
108+
protected _params = this._route.params;
124109

125-
items = toObservable(this.params).pipe(
126-
switchMap(params =>
127-
params?.section ? this._docItems.getItems(params.section) : Promise.resolve(null),
128-
),
110+
items = this._params.pipe(
111+
switchMap(params => (params?.section ? this._docItems.getItems(params.section) : of([]))),
129112
);
130113
}
131114

0 commit comments

Comments
 (0)