I am trying to redirect the user to a particular url on the click of back button in browser, and here is the code
constructor(private router: Router,private location: PlatformLocation) {
let eventUrl = window.sessionStorage.getItem('Event');
this.location.onPopState(() => {
alert('click');
this.router.navigate(['/', this.selectedLanguage, 'event', eventUrl]);
});
}
but it does not seem to fire the event when user click on back button. The code is in the current component. what is the issue?
EDIT
I tried with the below answer suggested, but that too does not seems to work, the function getting called , but it still redirects to the previous page rather than the mentioned url below
unload(event: any) {
let eventUrl = window.sessionStorage.getItem('buyerEvent');
this.router.navigateByUrl('/' + this.selectedLanguage + '/event/' + eventUrl);
}