Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property 'url' does not exist on type 'Event' for Angular2 NavigationEnd Event

    this.subscription = this.router.events.subscribe((event:Event) => {
        console.log(event.url); ##### Error : Property 'url' does not exist on type 'Event'.
   }

Typescript doesn't recognize the properties of the type Event that is built into the Angular Router. Is there something on tsd that I can use to solve this? Event is the super class of classes NaviagationEnd, NavigationStart

like image 446
BathgateIO Avatar asked Jul 15 '16 14:07

BathgateIO


1 Answers

You have to import { Event } from @angular/router;. Try moving console into the if block with condition.

this.subscription = this.router.events.subscribe((event:Event) => {
  if(event instanceof NavigationEnd ){
    console.log(event.url);
  }
});
like image 99
Arpit Agarwal Avatar answered Oct 01 '22 17:10

Arpit Agarwal