From 9e11795ea59395e2775257b41e3c141880aa9369 Mon Sep 17 00:00:00 2001 From: Lucas Li Date: Fri, 1 Nov 2024 16:59:42 -0700 Subject: [PATCH] reset metaTag on page changing --- .../src/main/angular/src/app/app.component.ts | 23 +++++++++++-------- .../incident-header-panel.component.ts | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/client/wfnews-war/src/main/angular/src/app/app.component.ts b/client/wfnews-war/src/main/angular/src/app/app.component.ts index 2efd58454..2ae498117 100644 --- a/client/wfnews-war/src/main/angular/src/app/app.component.ts +++ b/client/wfnews-war/src/main/angular/src/app/app.component.ts @@ -11,7 +11,7 @@ import { import { MatDialog } from '@angular/material/dialog'; import { MatIconRegistry } from '@angular/material/icon'; import { DomSanitizer, Meta, Title } from '@angular/platform-browser'; -import { Router } from '@angular/router'; +import { NavigationEnd, Router } from '@angular/router'; import { AppConfigService, TokenService } from '@wf1/core-ui'; import { RouterLink, @@ -37,6 +37,7 @@ import { } from '@app/services/capacitor-service'; import { CommonUtilityService } from '@app/services/common-utility.service'; import { App, URLOpenListenerEvent } from '@capacitor/app'; +import { filter } from 'rxjs/operators'; export const ICON = { ADVISORIES: 'advisories', @@ -272,20 +273,22 @@ export class AppComponent implements OnDestroy, OnInit, AfterViewInit { ); } - this.setMetaTags(); + this.router.events + .pipe(filter(event => event instanceof NavigationEnd)) + .subscribe(() => { + this.setDefaultMetaTags(); + }); } - setMetaTags(){ + setDefaultMetaTags(){ const imageUrl = this.appConfigService.getConfig().application.baseUrl.toString() + 'assets/images/share-wildfire.png'; this.titleService.setTitle('BC Wildfire Service'); - this.metaService.addTags([ - { property: 'og:title', content: 'BC Wildfire Service' }, - { property: 'og:image', content: imageUrl }, - { property: 'og:site_name', content: 'BC Wildfire Service' }, - { name: 'twitter:card', content: 'BC Wildfire Service' }, - { name: 'twitter:site', content: '@BCGovFireInfo' }, - ]); + this.metaService.updateTag({ property: 'og:title', content: 'BC Wildfire Service' }); + this.metaService.updateTag({ property: 'og:image', content: imageUrl }); + this.metaService.updateTag({ property: 'og:site_name', content: 'BC Wildfire Service' }); + this.metaService.updateTag({ name: 'twitter:card', content: 'summary_large_image' }); + this.metaService.updateTag({ name: 'twitter:site', content: '@BCGovFireInfo' }); } initializeDeepLinks() { diff --git a/client/wfnews-war/src/main/angular/src/app/components/public-incident-page/incident-info-header/incident-header-panel.component.ts b/client/wfnews-war/src/main/angular/src/app/components/public-incident-page/incident-info-header/incident-header-panel.component.ts index a009b1e0a..772153f86 100644 --- a/client/wfnews-war/src/main/angular/src/app/components/public-incident-page/incident-info-header/incident-header-panel.component.ts +++ b/client/wfnews-war/src/main/angular/src/app/components/public-incident-page/incident-info-header/incident-header-panel.component.ts @@ -149,7 +149,7 @@ export class IncidentHeaderPanelComponent implements AfterViewInit, OnInit { } } } - this.metaService.updateTag({ property: 'og:title', content: `Evacuation Alert for ${this.incident?.incidentName}`}); + this.metaService.updateTag({ property: 'og:title', content: `${this.incident?.incidentName}`}); } ngAfterViewInit(): void {