Changing states using stateProvider in ionic


#1

app.js

.config(function($stateProvider,$urlRouterProvider){
  $stateProvider
  .state('Login',{
    url:'/login',
    onEnter:["$state","$localStorage", '$rootScope' , '$ionicViewSwitcher', function($state,$localStorage, $rootScope, $ionicViewSwitcher){
        if((typeof($localStorage.userInfo)!== 'undefined') && (Object.keys($localStorage.userInfo).length !== 0)) {
                       $ionicViewSwitcher.nextTransition('none');
                     $state.go("Deployment");

        }
    }],
    templateUrl:'templates/login.html',
    controller:'LoginCtrl'

  })
  .state('Deployment',{
    url:'/deployment',
    templateUrl:'templates/deployment.html',
    cache : false
  })
  .state('Bill',{
    url:'/bills',
    templateUrl:'templates/bills.html',
    cache : false
  })

$urlRouterProvider.otherwise(function ($injector) {
           var $state = $injector.get('$state');
            $state.go('Login');
        });

});



controller:

$scope.billsDetails=function(deploymentId,startingDate,name){
$state.go(‘Bill’, {}, {reload:true});
}

When It goes to state Bill, the url changes from the url of previous state. to that of Bill and then instantly changes to localhost:8100/#.

That is:

1.localhost:8100/#/urlOfPreviousState

  1. localhost:8100/#Bill

  2. localhost:8100:/#

Even though it stays at the Bill state, url changes to #. I am concerned since it is creating problem with back button. On first tap at back button, it goes to /#/Bill and on second to /#/urlOffpreviousState


#2

Could you please add a sample snippet in codepen or plunker if possible?