1

I want to detect when page is refresh, for example the user press F5:

@HostListener('window:beforeunload') goToPage() {
    this.router.navigate(['../../login']);
}

I try something like this but event is not trigger and goToPage() is not called.

smn.tino
  • 2,272
  • 4
  • 32
  • 41
Wojciech Abacki
  • 251
  • 1
  • 4
  • 17

1 Answers1

2

your code is correct, but you can't stop browser refresh the page after router navigate to another page

I create a sample for you, hope it can help you.

live example

more references

Chunbin Li
  • 2,196
  • 1
  • 17
  • 31