I want to monitor routing events in an angular app and maybe change the past during certain conditions. I wrote the following class:
import {Event, RouterEvent, Router} from '@angular/router';
import {filter} from "rxjs";
@Injectable({
providedIn: 'root'
})
export class RounterListenerService implements OnInit{
constructor(private router: Router) {
}
ngOnInit() {
this.router.events.pipe(
filter((e: Event): e is RouterEvent => e instanceof RouterEvent)
).subscribe((e: RouterEvent) => {
console.log("navigated");
});
}
}```
When I implement this, nothing happens when I navigate. I have checked and the whole class does not seem to be initiated. So I guess I need it to include it in the project somehow, but I do not know how? So any way I can get this to work?