christopherthielen / ui-router-extras

THIS PROJECT IS NO LONGER MAINTAINED -- Extras for UI-Router for AngularJS. Sticky States (a.k.a. parallel states), Deep State Redirect (for tab-like navigation), Future States (async state definition)
http://christopherthielen.github.io/ui-router-extras/
MIT License
917 stars 211 forks source link

Invalid logic determining if state exists results in attempt to redefine existing state #313

Open adamlunger opened 8 years ago

adamlunger commented 8 years ago

I ran into an issue where ui-router was throwing a "State [name] is already defined" error. In trying to figure out why there was an attempt to redefined the same state, I traced it to the following line: https://github.com/christopherthielen/ui-router-extras/blob/master/src/future.js#L189. The same guard is repeated here: https://github.com/christopherthielen/ui-router-extras/blob/master/src/future.js#L238.

It seems to me this is supposed to read "If the state is not defined, then register the state", but that is not what the logic accomplishes.

state && (!$state.get(state) || (state.name && !$state.get(state.name))) says "If the state is not defined by reference or the state is not defined by name, then register the state". The guard will pass if the state is not found by reference and it will incorrectly attempt to register an existing state. The logic should be state && !($state.get(state) || (state.name && $state.get(state.name))).

christopherthielen commented 8 years ago

PR Welcomed!