ionic中登陆逻辑控制

问题

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

解决方案

登陆成功后,清除导航历史堆栈。

具体代码

menu.html

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

controllers.js

.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();
    });
});
原文地址:https://www.cnblogs.com/tonge/p/5696042.html