import { Component , OnInit } from '@angular/core' ; import { Router , ActivatedRouteSnapshot , NavigationEnd , NavigationError } from '@angular/router' ; import { JhiLanguageHelper } from 'app/core' ; @ Component ( { selector : 'jhi-main' , templateUrl : './main.component.html' } ) export class JhiMainComponent implements OnInit { constructor ( private jhiLanguageHelper , private router ) { } private getPageTitle ( routeSnapshot ) { let title = routeSnapshot . data && routeSnapshot . data [ 'pageTitle' ] ? routeSnapshot . data [ 'pageTitle' ] : 'frontendApp' ; if ( routeSnapshot . firstChild ) { title = this . getPageTitle ( routeSnapshot . firstChild ) || title ; } return title ; } ngOnInit ( ) { this . router . events . subscribe ( event => { if ( event instanceof NavigationEnd ) { this . jhiLanguageHelper . updateTitle ( this . getPageTitle ( this . router . routerState . snapshot . root ) ) ; } if ( event instanceof NavigationError && event . error . status === 404 ) { this . router . navigate ( [ '/404' ] ) ; } } ) ; } }