I'm currently trying to detect when a route changes and a new view (HTML) is replaced.
I attempted the code below but I'm unsure of how to proceed from here.
this._routerSub = this.router.events
.filter(event => event instanceof NavigationEnd)
//.do(event => console.log(event)) //
.subscribe((value) => { });
I also tried the following code but encountered an error:
Argument of type Event is not assignable to parameter of type '(value:Event)=>void'.
import { Router, NavigationEnd, Event } from '@angular/router';
this._routerSub = this.router.events
.subscribe(event: Event) => {
if (event instanceof NavigationEnd) {
console.log(event.url);
}
});
Below are my app.component.ts and app.component.ts code. Shouldn't it call onActivate on activation? The router outlet will emit an activate event every time a new component is instantiated.
app.component.html
<router-outlet (activate)="onActivate($event)" ></router-outlet>
app.component.ts
onActivate(e) {
debugger;
console.log(1);
}