Ok, I have two use cases for my question:
I am working on an application that has a route /en/register . Everything works well when I am at the root and I click on the button that makes this.router.navigate([this.routeParams.lang, 'register']); , and all this is good, it opens the modal constructor (or ngOnInit, anyways) with ($('#modalRegister') as any).modal('show'); .
Everything works fine, but if I close the modal, the route is still /en/register/ (yes, I can get it to go to /en , but look at usage example # 2 before suggesting this), so when I click the button she does nothing. Neither the constructor nor ngOnInit are called, not route.params.subscribe () or route.url.subscribe () (which I think they should ...).
In the same application, I have a button that searches and centers some markers on the map (in /en/search/blah ). This is all good if I'm on the index page or if I change the search query. However, if the user drags the map somewhere else and wants to center the same markers again, I also do this.router.navigate(['search', this.searchQuery]); , and if it ends with the same route (for example, double-click the search button), this does not do anything.
Although I agree that the components will not be recreated if the URL has not changed, this is a bad design because in the UI router you can do the same and it will work (as far as I can remember).
So, in Angular 4, how do I run the same code in the constructor / ngOnInit of the route component when the same URL is sent for navigation? or how to determine if the url matches and act accordingly? (although I still think this is a bad design, but anyway ...).
Any advice is appreciated. Thanks!
source share