/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import { inject, Injectable } from '@angular/core'; import { Title } from '@angular/platform-browser'; import { PRIMARY_OUTLET, RouteTitleKey } from './shared'; import * as i0 from "@angular/core"; import * as i1 from "@angular/platform-browser"; /** * Provides a strategy for setting the page title after a router navigation. * * The built-in implementation traverses the router state snapshot and finds the deepest primary * outlet with `title` property. Given the `Routes` below, navigating to * `/base/child(popup:aux)` would result in the document title being set to "child". * ``` * [ * {path: 'base', title: 'base', children: [ * {path: 'child', title: 'child'}, * ], * {path: 'aux', outlet: 'popup', title: 'popupTitle'} * ] * ``` * * This class can be used as a base class for custom title strategies. That is, you can create your * own class that extends the `TitleStrategy`. Note that in the above example, the `title` * from the named outlet is never used. However, a custom strategy might be implemented to * incorporate titles in named outlets. * * @publicApi * @see [Page title guide](guide/router#setting-the-page-title) */ export class TitleStrategy { /** * @returns The `title` of the deepest primary route. */ buildTitle(snapshot) { let pageTitle; let route = snapshot.root; while (route !== undefined) { pageTitle = this.getResolvedTitleForRoute(route) ?? pageTitle; route = route.children.find(child => child.outlet === PRIMARY_OUTLET); } return pageTitle; } /** * Given an `ActivatedRouteSnapshot`, returns the final value of the * `Route.title` property, which can either be a static string or a resolved value. */ getResolvedTitleForRoute(snapshot) { return snapshot.data[RouteTitleKey]; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TitleStrategy, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TitleStrategy, providedIn: 'root', useFactory: () => inject(DefaultTitleStrategy) }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TitleStrategy, decorators: [{ type: Injectable, args: [{ providedIn: 'root', useFactory: () => inject(DefaultTitleStrategy) }] }] }); /** * The default `TitleStrategy` used by the router that updates the title using the `Title` service. */ export class DefaultTitleStrategy extends TitleStrategy { constructor(title) { super(); this.title = title; } /** * Sets the title of the browser to the given value. * * @param title The `pageTitle` from the deepest primary route. */ updateTitle(snapshot) { const title = this.buildTitle(snapshot); if (title !== undefined) { this.title.setTitle(title); } } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DefaultTitleStrategy, deps: [{ token: i1.Title }], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DefaultTitleStrategy, providedIn: 'root' }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DefaultTitleStrategy, decorators: [{ type: Injectable, args: [{ providedIn: 'root' }] }], ctorParameters: function () { return [{ type: i1.Title }]; } }); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGFnZV90aXRsZV9zdHJhdGVneS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uL3BhY2thZ2VzL3JvdXRlci9zcmMvcGFnZV90aXRsZV9zdHJhdGVneS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0dBTUc7QUFFSCxPQUFPLEVBQUMsTUFBTSxFQUFFLFVBQVUsRUFBQyxNQUFNLGVBQWUsQ0FBQztBQUNqRCxPQUFPLEVBQUMsS0FBSyxFQUFDLE1BQU0sMkJBQTJCLENBQUM7QUFHaEQsT0FBTyxFQUFDLGNBQWMsRUFBRSxhQUFhLEVBQUMsTUFBTSxVQUFVLENBQUM7OztBQUV2RDs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OztHQXNCRztBQUVILE1BQU0sT0FBZ0IsYUFBYTtJQUlqQzs7T0FFRztJQUNILFVBQVUsQ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