import { Component, Input, OnInit } from '@angular/core'; import { Router, Route } from '@angular/router'; @Component({ selector: 'app-hero', templateUrl: './hero.component.html', styleUrls: ['./hero.component.scss'], }) export class HeroComponent implements OnInit { @Input() public description: string; @Input() public designFileLink: string = 'https://zeplin.io/'; @Input() public fileIcon: string = 'sketch'; @Input() public fileLocation: string = 'View Sketch Assets'; @Input() public version: number; @Input() public packageSrc: string; @Input() public title: string; public package: string; public showDevRef: boolean = false; public showUsage: boolean = false; public showComponentStyles: boolean = false; public showLibrary: boolean = false; public showResponsive: boolean = false; public showStyle: boolean = false; constructor(private router: Router) {} public ngOnInit(): void { this.checkRoutes(); } private checkRoutes(): void { const rootRouteName: string = this.router.url.split('/')[1]; if (rootRouteName) { // gracefully handle unpopulated routes const routeChildren: Route[] = this.router.config.find((route: Route) => { return route.path === rootRouteName; }).children; if (routeChildren) { // gracefully handle routes without children this.showDevRef = !!routeChildren.find((route: Route) => { return route.path === 'developer-reference'; }); this.showUsage = !!routeChildren.find((route: Route) => { return route.path === 'usage'; }); this.showStyle = !!routeChildren.find((route: Route) => { return route.path === 'style'; }) this.showComponentStyles = !!routeChildren.find((route: Route) => { return route.path === 'component-styles'; }); this.showLibrary = !!routeChildren.find((route: Route) => { return route.path === 'library'; }); this.showResponsive = !!routeChildren.find((route: Route) => { return route.path === 'responsive'; }); } } } }