I have a common navbar component that is included in every page of my website.
I would like it to detect when the URL changes using a HostListener.
@HostListener('window:hashchange', ['$event'])
onHashChange(event) {
this.checkCurrentURL();
}
private checkCurrentURL(){
console.log("location: "+window.location.pathname)
}
Unfortunately, the current implementation does not seem to be working. Any suggestions?
EDIT: SOLUTION
I have discovered a solution that does not involve HostListener, but it is effective.
constructor(private router : Router){
router.events.subscribe((val) => {
this.checkCurrentURL();
});
}