import { Platform } from '@angular/cdk/platform' ; import { DOCUMENT } from '@angular/common' ; import { ChangeDetectionStrategy , Component , Inject , OnInit } from '@angular/core' ; import { ActivatedRoute , Router } from '@angular/router' ; @ Component ( { selector : 'main-lang-redirect' , templateUrl : './lang-redirect.component.html' , styleUrls : [ './lang-redirect.component.scss' ] , changeDetection : ChangeDetectionStrategy . OnPush , } ) export class LangRedirectComponent implements OnInit { constructor ( private route , private router , @ Inject ( DOCUMENT ) private doc , private platform ) { } ngOnInit ( ) { this . route . url . subscribe ( url => { const newUrl = url . map ( u => u . path ) ; const link = this . doc . createElement ( 'link' ) ; link . setAttribute ( 'rel' , 'canonical' ) ; link . setAttribute ( 'href' , `https://ngrefs.com/${ newUrl . join ( '/' ) }` ) ; this . doc . head . appendChild ( link ) ; if ( this . platform . isBrowser ) { this . router . navigate ( newUrl ) ; } } ) ; } }