angular-ui / ui-router

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

State redirects don't cancel the resolves #3611

Closed jutaz closed 4 years ago

jutaz commented 6 years ago

This is a (check one box):

My version of UI-Router is: 1.0.4

Bug Report

Current Behavior:

Give the following pseudo-example of the route configuration (used AngularJS as base):

// First state.
{
  name: 'state1',
  resolve: {
    dependency: ['$state', ($state) => {
      if (something) {
        return $state.go('state2');
      }
      return {
        id: 1,
        submodel: {
          id: 2
        }
      }
    }],
    anotherDependency: ['dependency', (dependency) => {
      return dependency.submodel.id;
    }]
  },
  template: 'State 1'
};
// 2nd state.
{
  name: 'state2',
  template: 'State 2'
}

If one is navigating to state1 and logic for redirection ($state.go) is triggered, anotherDependency will still run, causing it to error out, due to dependency not having a submodel, as instead of being injected with an expected Object, its value becomes the Transition object.

Note that using $transition$.abort() has no effect in this case.

Currently the only way to prevent this is to reject dependency resolve, but that produces an error of type 6, which isn't what actually is happening.

Expected Behavior:

I would expect further resolves not to execute if a resolve starts a new transition, which superseeds the current one.

Link to Plunker or stackblitz that reproduces the issue:

https://ui-router-angularjs-rrdmns.stackblitz.io

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

This does not mean that the issue is invalid. Valid issues may be reopened.

Thank you for your contributions.