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 does not recognize properties of the Event type built into the Angular router. Is there something in tsd that I can use to solve this problem? Event is a superclass of NaviagationEnd, NavigationStart classes
+4
BathgateIO
source
to share
1 answer
You should import { Event } from @angular/router;
. Try moving the console to a if
conditional block .
this.subscription = this.router.events.subscribe((event:Event) => {
if(event instanceof NavigationEnd ){
console.log(event.url);
}
});
+7
Arpit Agarwal
source
to share