Issue
I'm seeing one subscription to router.events yield three calls per route change to the callback function, and each reports instanceof event as ActivationEnd.
console.log('This code runs only once, at site initialization.');
router.events.subscribe((event: RouterEvent) => {
if (event instanceof ActivationEnd) {
console.log('This should only log once per route change, but logs three times.');
};
});
I found this thread on Github, which seems related, but I'm having a hard time believing this is still an issue...
I'm using Angular 5 (5.2.10).
UPDATE: It appears that this event is getting fired once for each route segment... Checking documentation.
Solution
It appears that I should be using NavigationEnd instead of ActivationEnd to achieve the desired result. I should have known that. I think my eyes failed to notice the difference.
Answered By - BBaysinger
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.