Ниже код моего компонента:
import { Component } from '@angular/core'; import { Router, ActivatedRoute } from '@angular/router'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { showMenu:any=''; constructor(router:Router) { router.events.forEach((event) => { if(event instanceof NavigationStart) { this.showMenu = event.url !== "/newsection"; console.log(event.url); } }); } }
Я получаю ошибку:
ReferenceError: NavigationStart не определено
Заменить:
import { Router, ActivatedRoute } from '@angular/router';
по:
import { Router, NavigationStart } from '@angular/router';
Тогда вы можете подписаться так:
router.events.subscribe(event => { if(event instanceof NavigationStart) { // ... } }
import { Component } from '@angular/core'; import { Router, ActivatedRoute,NavigationStart } from '@angular/router'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { showMenu:any=''; constructor(router:Router) { router.events.forEach((event) => { if(event instanceof NavigationStart) { this.showMenu = event.url !== "/newsection"; console.log(event.url); } }); } }