I see these new events in the new Angular 2 Router.
Theres NavigationStart, NavigationEnd, NavigationFailed (or something like that)
Does anyone know how to use these yet? I've messed around with a few things but haven't been able to get them to do anything.
The Angular Routers triggers several events starting with when the Navigation starts ( NavigationStart ) and also when the Navigation end ( NavigationEnd ) successfully. It is triggered when the navigation is canceled either by the user ( NavigationCancel ) or due to an error in the navigation ( NavigationError).
NavigationEndlinkAn event triggered when a navigation ends successfully. class NavigationEnd extends RouterEvent { constructor(id: number, url: string, urlAfterRedirects: string) type: EventType.
The Router provides an events observable that can be subscribed to
constructor(router:Router) { router.events.subscribe(event => { if(event instanceof NavigationStart) { } // NavigationEnd // NavigationCancel // NavigationError // RoutesRecognized } }); See also
NOTE
don't forget to import NavigationStart from router module
import { Router, NavigationStart } from '@angular/router'; because if you don't import it instanceof will not work and an error NavigationStart is not defined will rise.
Just like this
constructor( private router:Router ){} this.router.events .filter(event=> event instanceof NavigationStart) .subscribe((event:NavigationStart)=>{ // TODO });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With