在离子中使用stateProvider改变状态

时间:2015-09-03 17:28:31

标签: ionic

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');
        });

});

控制器:

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

当它进入状态Bill时,网址会从之前状态的网址更改。比尔的那个,然后立即改为localhost:8100/#

那是:

1。localhost:8100/#/urlOfPreviousState

  1. localhost:8100/#Bill

  2. localhost:8100:/#

  3. 即使它保持在Bill状态,url也会更改为#。我担心因为它会产生后退按钮的问题。在第一次点击后退按钮时,它会进入 /#/Bill以及/#/urlOffpreviousState

    的第二位

1 个答案:

答案 0 :(得分:1)

只需改变这样的状态:

$state.go('Bill');