You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I came across this subtle bug while implementing two distinct "zones" in my app -- namely a "visitors only" zone and a "members only" zone. This is tested with Angular 1.5.1 and UI Router 0.2.18
Consider this scenario:
root state is an abstract state that dynamically loads (through a resolve) the current user's profile. This resolve is injected into direct child states to make sure they're not instanciated before the profile is finished loading
child state 1's own resolve checks if the user is registered. If so, the resolve is rejected and the user redirected to child state 2
child state 2's own resolve checks if the user is not registered. If so, the resolve is rejected and the user redirected to child state 1
So, in effect: child state 1 is my "visitors only" zone while child state 2 is my "members only" zone.
Now, assume I am a registered user. When I first launch the app, here's what happens:
root state is resolved, my user profile is loaded
child state 1's resolve is rejected (since I'm a member) and I am redirected to child state 2
root state is resolved again! (and the API to load the profile is called again...)
child state 2' is resolved and successfully activated
In my understanding, step 3 shouldn't happen -- root's already been resolved previously and should not be resolved gain. Or am I getting something wrong?
Note this only happens on the app's initial launch; if I try to navigate to state 1 (eg. by clicking an ui-sref), then only state 1's resolve is tested and correctly rejected without root state being resolved again.
In my understanding, step 3 shouldn't happen -- root's already been resolved previously and should not be resolved gain. Or am I getting something wrong?
You are misunderstanding. The initial transition is cancelled and a brand new one started (when you do your check and redirect). Think of each transition as atomic; it either happens fully or not at all.
The 1.0 release is specifically addressing this use case. We support redirects from parent to child states while retaining previously resolved values.
I'll leave this ticket open and make sure it works before 1.0 final
You are misunderstanding. The initial transition is cancelled and a brand new one started (when you do your check and redirect). Think of each transition as atomic; it either happens fully or not at all.
Oh, I see. Well, I think that I can live with a flag in root's resolve to make sure the API isn't called twice ;)
The 1.0 release is specifically addressing this use case. We support redirects from parent to child states while retaining previously resolved values.
Can't wait to try the production-ready version, then.
I came across this subtle bug while implementing two distinct "zones" in my app -- namely a "visitors only" zone and a "members only" zone. This is tested with Angular 1.5.1 and UI Router 0.2.18
Consider this scenario:
So, in effect: child state 1 is my "visitors only" zone while child state 2 is my "members only" zone.
Now, assume I am a registered user. When I first launch the app, here's what happens:
In my understanding, step 3 shouldn't happen -- root's already been resolved previously and should not be resolved gain. Or am I getting something wrong?
Note this only happens on the app's initial launch; if I try to navigate to state 1 (eg. by clicking an
ui-sref
), then only state 1's resolve is tested and correctly rejected without root state being resolved again.I've made a Plunker to demonstrate: https://plnkr.co/edit/Nne19FArvUf0W4JHOtB7
The text was updated successfully, but these errors were encountered: