@@ -11,10 +11,11 @@ import {Component, OnDestroy, ViewEncapsulation, inject} from '@angular/core';
1111import { AnalyticsService } from './shared/analytics/analytics' ;
1212import { NavigationFocusService } from './shared/navigation-focus/navigation-focus.service' ;
1313import { Subscription } from 'rxjs' ;
14- import { map , pairwise , startWith } from 'rxjs/operators' ;
15- import { RouterOutlet } from '@angular/router' ;
14+ import { filter , map , pairwise , startWith } from 'rxjs/operators' ;
15+ import { NavigationEnd , Router , RouterOutlet } from '@angular/router' ;
1616import { NavBar } from './shared/navbar/navbar' ;
1717import { CookiePopup } from './shared/cookie-popup/cookie-popup' ;
18+ import { HeaderTagManager } from './shared/header-tag-manager' ;
1819
1920@Component ( {
2021 selector : 'material-docs-app' ,
@@ -29,10 +30,12 @@ import {CookiePopup} from './shared/cookie-popup/cookie-popup';
2930} )
3031export class MaterialDocsApp implements OnDestroy {
3132 private _subscriptions = new Subscription ( ) ;
33+ private _headerTagManager = inject ( HeaderTagManager ) ;
3234
3335 constructor ( ) {
3436 const analytics = inject ( AnalyticsService ) ;
3537 const navigationFocusService = inject ( NavigationFocusService ) ;
38+ const router = inject ( Router ) ;
3639
3740 this . _subscriptions . add (
3841 navigationFocusService . navigationEndEvents
@@ -50,11 +53,24 @@ export class MaterialDocsApp implements OnDestroy {
5053 analytics . locationChanged ( toUrl ) ;
5154 } ) ,
5255 ) ;
56+
57+ router . events
58+ . pipe (
59+ filter ( ( e ) : e is NavigationEnd => e instanceof NavigationEnd ) ,
60+ map ( event => event . urlAfterRedirects ) ,
61+ )
62+ . subscribe ( url => {
63+ this . _updateCanonicalLink ( url ) ;
64+ } ) ;
5365 }
5466
5567 ngOnDestroy ( ) {
5668 this . _subscriptions . unsubscribe ( ) ;
5769 }
70+
71+ private _updateCanonicalLink ( absoluteUrl : string ) {
72+ this . _headerTagManager . setCanonical ( absoluteUrl ) ;
73+ }
5874}
5975
6076function resetScrollPosition ( ) {
0 commit comments