Running event.preventDefault () on $ stateChangeStart creates a duplicate state

oneand twoare states created using ui-router with urls /oneand /two. Suppose I navigate through the following states:

twoone

(in the browser bar I see /two/one)

Then I click the back button, but instead of switching to, twoI intentionally prevent the state from changing as follows:

   $scope.firstTime = true;

   $rootScope.$on('$stateChangeStart',
        function(event, toState, toParams, fromState, fromParams){
          if ($scope.firstTime) {
            event.preventDefault();
            $scope.firstTime = false;
          }
        });

Now I click again, this time the state change is not prevented, but instead of returning to two, ui-router remains in state one( /one) .... now if I click back again. I can return to state two( /two).

ui-router one ?

+3

All Articles