From b34648389ca8e0247e9994541317eae9a13b9cdd Mon Sep 17 00:00:00 2001 From: softsimon Date: Sun, 19 Jul 2020 22:49:06 +0700 Subject: [PATCH] Restoring dynamic canonical URL. --- .../src/app/components/app/app.component.ts | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/frontend/src/app/components/app/app.component.ts b/frontend/src/app/components/app/app.component.ts index faf129308..b54af73c1 100644 --- a/frontend/src/app/components/app/app.component.ts +++ b/frontend/src/app/components/app/app.component.ts @@ -1,5 +1,5 @@ -import { Component, HostListener } from '@angular/core'; -import { Router } from '@angular/router'; +import { Component, HostListener, OnInit } from '@angular/core'; +import { Router, NavigationEnd } from '@angular/router'; import { WebsocketService } from '../../services/websocket.service'; import { StateService } from 'src/app/services/state.service'; @@ -8,8 +8,7 @@ import { StateService } from 'src/app/services/state.service'; templateUrl: './app.component.html', styleUrls: ['./app.component.scss'] }) -export class AppComponent { - network = ''; +export class AppComponent implements OnInit { link: HTMLLinkElement; constructor( @@ -26,4 +25,22 @@ export class AppComponent { this.stateService.keyNavigation$.next(event); } + ngOnInit() { + this.router.events.subscribe((val) => { + if (val instanceof NavigationEnd) { + this.updateCanonicalUrlElement('https://mempool.space' + location.pathname); + } + }); + } + + updateCanonicalUrlElement(url: string) { + if (!this.link) { + this.link = window.document.createElement('link'); + this.link.setAttribute('rel', 'canonical'); + window.document.head.appendChild(this.link); + } + this.link.setAttribute('href', url); + } + + }