ionic中登录逻辑控制

问题

登录成功后从login.html调转到home.html,此时在home页面按back键又回到了login.html 。html

解决方案

登录成功后,清除导航历史堆栈。缓存

具体代码

menu.htmlionic

<ion-item style="positive" nav-clear menu-close ng-href="#/login" ng-click="logout()">注销</ion-item>

controllers.jscode

.controller('AppCtrl', function ($scope) { 
    // 注销登录
    $scope.logout = function () {
        // 清除缓存帐号
        window.localStorage.removeItem(cache.user);
    }
}).
.controller('LoginCtrl',function($scope,$state,UserService){
    UserService.login(data, function (response) {
        //登录成功
        if (response.state == 1) {
            // 跳转到首页
            $state.go('home');
        }           
    }
})
.controller('HomeCtrl',function($scope,$ionicHistory){
    //在首页中清除导航历史退栈
    $scope.$on('$ionicView.afterEnter', function () {
        $ionicHistory.clearHistory();
    });
});
相关文章
相关标签/搜索