/
githubmirror
/
angular
Обзор
Документация
Войти
/
githubmirror
/
angular
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
adev/src/app/core/services/a-dev-title-strategy.ts
60 строк
2 KB
Matthieu Riegler
docs(docs-infra): Use `@Service` instead of `@Injectable`
23 апр 2026, 21:21
23 апр 2026, 21:21
7414352
Код
Авторство
О чём код?
/*! * @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.dev/license */ import {inject, Service} from '@angular/core'; import {NavigationItem} from '@angular/docs'; import {Meta, Title} from '@angular/platform-browser'; import {ActivatedRouteSnapshot, RouterStateSnapshot, TitleStrategy} from '@angular/router'; export const ROUTE_TITLE_PROPERTY = 'label'; export const ROUTE_PARENT_PROPERTY = 'parent'; export const TITLE_SUFFIX = 'Angular'; export const TITLE_SEPARATOR = ' • '; export const DEFAULT_PAGE_TITLE = 'Overview'; export const TITLE_OG_META_TAG = 'og:title'; export const TITLE_TWITTER_META_TAG = 'twitter:title'; export const ALL_TITLE_META_TAGS = [TITLE_OG_META_TAG, TITLE_TWITTER_META_TAG]; @Service() export class ADevTitleStrategy extends TitleStrategy { private readonly title = inject(Title); private readonly meta = inject(Meta); constructor() { super(); } override updateTitle(routerState: RouterStateSnapshot) { const title = this.buildTitle(routerState); if (title !== undefined) { this.title.setTitle(title); ALL_TITLE_META_TAGS.forEach((tag) => this.meta.updateTag({property: tag, content: title})); } } override buildTitle(snapshot: RouterStateSnapshot): string { let route: ActivatedRouteSnapshot = snapshot.root; while (route.firstChild) { route = route.firstChild; } const data = route.data as NavigationItem; const routeTitle = data.label ?? ''; const prefix = routeTitle.startsWith(DEFAULT_PAGE_TITLE) && data.parent ? `${data.parent.label}${TITLE_SEPARATOR}` : ''; return !!routeTitle ? `${prefix}${routeTitle}${TITLE_SEPARATOR}${TITLE_SUFFIX}` : TITLE_SUFFIX; } }