Issue
I want to detect when a page is refreshed using a router in my single-page application (Angular project).
Is there an alternate way?
Solution
Try this:
  this.router.events
    .pipe(filter((rs): rs is NavigationEnd => rs instanceof NavigationEnd))
    .subscribe(event => {
      if (
        event.id === 1 &&
        event.url === event.urlAfterRedirects
      ) {
          // Your code here for when the page is refreshd
      }
    })
You will need to import
import { filter } from 'rxjs/operators'
import { Router  } from '@angular/router';
Answered By - Ghoul Ahmed
 
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.