Back button event does not fire Angular

Home / Uncategorized / Back button event does not fire Angular

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(() => {
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?

You can bind things you want to do while leaving the app to window.unload event. Here I used the HostListener.
@HostListener(‘window: unload’, [‘$event’])
unload(event) {‘https://localhost:4200’, ‘_blank’);

Mention that Chrome will block by default, you have to change block policy.
Read more

Leave a Reply

Your email address will not be published. Required fields are marked *