Resolver not called when upstream params change
See original GitHub issueI’m submitting a … (check one with “x”)
[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
Resolvers are not called when an upstream route param changes. This is wrong as the parent route param may obviously have significance. e.g company/1/employee/2 company/2/employee/2 Employee 2 is not the same employee even though the param is 2 in both cases.
Expected behavior
The resolver would be called and could fetch the proper data which would then be made available to component as route data
Minimal reproduction of the problem with instructions
See https://github.com/slubowsky/resolve-issue Run the app (ng serve). Click on the links to navigate. Going to / from “1 and 1” to / from either of the others results in resolver being called and message being logged to the console. Going between “1 and 2” and “2 and 2” does not. Resolver is never called. Component would not be updated.
What is the motivation / use case for changing the behavior?
Its currently broken. Cant keep component current with route using a resolver and route.data.
Thinking about this a bit more, can it be that the design is such that resolvers are only meant to be called before a component is shown for the first time (to prevent “blank” component), but once a component is showing, the resolver and route.data are never meant to be called and updated even if the route changes? If this is the case, then I need to handle the exact same thing, getting route params and fetching the appropriate data, in two places. First get the params and fetch the data in the resolver and subscribe to ActivatedRoute.data for the first update, and then do the same thing again whenever the route changes.
Bigger problem is that I have no way of knowing the route changed (ActivatedRoute.params is not updated either). I suppose we could subscribe to router events and get snapshot or something on NavigationEnd but things are getting very messy, multiple paths instead of one, cut and pasted code, etc… I hope this is just a bug…
Plus it does seem to be called when this route segments parameters change so things are really getting strange. Lots of different scenarios that all should be exactly the same but instead are all different…
Please tell us about your environment:
Windows 10, Visual Studio Code, Angular-cli 1.0.0-beta.20-4
- Angular version: 2.0.X
2.2.0
- Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
Only tried Chrome
-
Language: [all | TypeScript X.X | ES6/7 | ES5] Typescript 2.0.10
-
Node (for AoT issues):
node --version
=
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:11 (4 by maintainers)
The current behavior is by design.
Both strategies are reasonable in some use cases - it just happen that we have implemented the one that does not make sense in your use case.
What you can do is to inject the activatedRoute and load the Employee in your component.
@vicb I’m sorry but I’m really tired of hearing “The current behavior is by design” and similar sentences. Could you please provide us The Design, so we would know how are we supposed to use router?
Currently there are so many pitfalls and I think there are quite a lot of people experiencing them. And surprisingly, most of them are by design.