I've been doing some research into reloading an Angular 4+ route and it looks as if the preferred method is to instead listen to URL parameter changes within the component and re-initialise the component there instead.
The issue I'm having is in trying to find a DRY (don't repeat yourself) approach to make this work across multiple components, when the URL would be identical (including parameters). In AngularJS this was simple with UI-router.
Use case:
I have a notification panel which can "float" above any route, when a notification is clicked it needs to go to the content it relates to - this can be many different types of content.
For example: /posts/:id
or /groups/:id
or /users/:id
If the user is already looking at that content it doesn't reload and refresh to reflect the message of the notification. I.e "John Doe commented on your post" (the user could be looking at an outdated version of that post) or "Jane Doe accepted your request to join Some Group" (the user could be looking at the guest view of that group).
I did look into using window.location.reload()
when detecting that the route is the same, and that works, but it's highly undesirable due to the overhead it causes (angular reinitialising, auth check, socket reconnection, etc).
Any suggestions would be greatly appreciated!
onSameUrlNavigation
setting? Default isignore
but there's areload
option as well. I don't have experience with it, though. – Gregoor