import { ChangeDetectionStrategy , Component , OnInit } from '@angular/core' ; import { ActivatedRoute , NavigationEnd , Router } from '@angular/router' ; import { IconsRegistry } from '@novyk/ikong' ; import { filter } from 'rxjs' ; import { icons } from '../../shared/icons' ; import { Breadcrumb } from './breadcrumb' ; @ Component ( { selector : 'app-root' , templateUrl : './app.component.html' , styleUrls : [ './app.component.scss' ] , changeDetection : ChangeDetectionStrategy . OnPush , } ) export class AppComponent implements OnInit { breadcrumbs : Breadcrumb [ ] [ ] = [ ] ; rootBreadcrumbs : Breadcrumb [ ] = [ { link : '/' , title : 'Home' , } , { link : '/cli' , title : 'Angular CLI' , } , { link : '/templates' , title : 'Templates' , } , ] ; url ? : string ; urlChunks ? : string [ ] ; constructor ( private route , private router , private iconsRegistry ) { this . iconsRegistry . add ( icons ) ; this . breadcrumbs = [ this . rootBreadcrumbs ] ; } ngOnInit ( ) { this . router . events . pipe ( filter ( e => e instanceof NavigationEnd ) ) . subscribe ( ( e ) => { this . url = e . url ; this . urlChunks = [ ] ; const chunks = e . url . split ( '/' ) ; chunks . shift ( ) ; let curr = '' ; chunks . forEach ( chunk => { curr += '/' + chunk ; this . urlChunks . push ( curr ) ; } ) ; this . urlChunks . push ( curr ) ; } ) ; } nav ( route ) { this . router . navigate ( [ route ] ) ; } defBreadcrumbs ( breadcrumbs ? ) { this . breadcrumbs = breadcrumbs ? [ this . rootBreadcrumbs , ... breadcrumbs , ] : [ this . rootBreadcrumbs ] ; } }