angular-ui / ui-router

The de-facto solution to flexible routing with nested views in AngularJS
http://ui-router.github.io/
MIT License
13.54k stars 3k forks source link

Returning new target based on promise resolution in onBefore not changing transition #3535

Closed ratrock closed 7 years ago

ratrock commented 7 years ago

This issue tracker is for Bug Reports and Feature Requests only. Please direct requests for help to StackOverflow. See http://bit.ly/UIR-SOF for details.

This is a:

My version of UI-Router is: 1.0.6

Bug Report

Current Behavior:

When resolving a promise in an onBefore or onStart hook, if this results in returning a different target state, the transition continues as if there was no change to the target.

Expected Behavior:

onBefore should wait for the promise to resolve and change state if a new target is returned.

Link to Plunker that reproduces the issue:

https://jsfiddle.net/yw19qud6/1/

In this example, if AuthService rejects, you should be redirected to state2 (if that isn't the transition already).

ratrock commented 7 years ago

Ugh, I just needed to do a "return auth.isAuthenticated().catch(() => ....)" and it worked.