Here is a plunker to play with:
https://plnkr.co/edit/qTjftING3Hk2fwN36bQa?p=preview
Everything works well, except when you manually change the id parameter in the url bar, because then the projects dropdown does not show the new projectId as current project. This happens when the user saves an url as favorite link and copy/paste it into the url bar! A common case I would say!
To fix this I can listen to route.params changes in the TestsListComponent
and add a check with a sharedService/EventEmitter
wheter the changed id exists in that dropdown. The bool return value existsProjectId inside the TestsListComponent decides wether I should redirect to the /projects
page because the id did not exist.
But honestly, redirecting from the TestsListComponent
is too late at least from a user experience perspective, because the route projects/:id/tests
is already activated.
How would you fix that misbehavior?
P.S.
Maybe there is kind of a global params change I can listen to and check the path and its id inside the ProjectsListComponent, that would help!
If someone knows how to edit the url bar of the plunkr in window mode to test that inconsistency please let me know how you made that readonly url bar editable... even copying the url into a new tab does not work, as I get a plunkr not found error... => ANSWER
- Load the plunkr and activate window mode
- In window mode copy/paste the url into a new tab
- When that is the pasted url: https://run.plnkr.co/LhwcQjzWHsRUda8H/projects/1/schoolclasses
- Make it that url: https://run.plnkr.co/LhwcQjzWHsRUda8H/#/projects/1/schoolclasses
- and change param: https://run.plnkr.co/LhwcQjzWHsRUda8H/#/projects/2/schoolclasses
- If you dont add the hash then you get a not found 404.
I'm not sure if i correctly understand your question, anyway here is my plunkr.
Just navigate to
#/projects/1/tests
.