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

Transitions twice when using uiCanExit on a state that has stateParams in URL #3560

Closed xphong closed 6 years ago

xphong commented 6 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: (version) 1.0

Bug Report

Code:

this.uiCanExit = function() {
    if (this.isFormDirty()) {
        return confirm('Are you sure');
    }
}

Current Behavior:

If on a state with state params (ex: /user?id=123), and user tries to exit. The transitions fire twice when pressing cancel on confirmation causing the pop up box to show up twice.

URL tries to go to /user-profile then when pressing cancel, goes back to /user without the stateParams.

Expected Behavior:

Transitions once and confirmation pops up only once. State should also keep current stateParams.

christopherthielen commented 6 years ago

Can you try with a more current version of ui-router? 1.0.11 is the latest released version. Also, please provide a plunker or stackblitz which demonstrates the issue.

Here's an example which seems to work: http://plnkr.co/edit/ZGyacN69GTjVlE5bJ001?p=preview