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

When URL routing, $stateChangeSuccess event is fired and controller is instantiated after request fails in the resolver. #3742

Closed mennaelkashef closed 5 years ago

mennaelkashef commented 5 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 (check one box):

My version of UI-Router is: (type version)

Bug Report

Current Behavior:

      .state('stateName', {
        url: '/',
        templateUrl: 'views/template.html',
        controller: 'stateCtrl',
        resolve: {
          data: function (dataService) {
            return dataService.getData()
              .then(function (response) {
                var data = response.data.data;
                return data;
              }, function (error) {
                console.log(error);
              });
          },
        },

When the dataService.getData() promise is rejected the redirection doesn't stop, the controller is instantiated and the $stateChangeSuccess event is fired. however when I remove the error handling part it works fine.

Expected Behavior:

When the dataService.getData() promise is rejected it should stop redirection, and it shouldn't instantiate the controller.