-1

I am working on an Angular 10 app, I would like to navigate to another component using (router.navigate) only when a page refreshes/reloads. How can i achieve this in Angular.

Thank you Awaiting responses

1 Answers1

0

The refresh of the page should trigger the event handler bound to window:beforeunload. 

import { Component, HostListener } from '@angular/core'; 
@Component({ ... }) 
export class HomeViewComponent { 
@HostListener("window:beforeunload", ["$event"])
 unloadHandler(event: Event) { 
console.log("Processing beforeunload...");
 // Do more processing...
 event.returnValue = false; 
} 
... 
}
Jobelle
  • 2,717
  • 1
  • 15
  • 26