从历史记录中删除页面,因此“返回"将正常工作历史记录、正常、页面、工作

2023-09-06 08:31:59 作者:莫名伤感。

我有我的应用,您需要登录才能进入其他页面.

I have my app that you need to login to get in to the other pages.

所以第一页是登录",它会检查您是否已经登录,如果是,您将被重定向到主页应用程序,如果没有,它将显示登录页面.

so the first page is "login" and it checks if you are already logged, if so you will be redirected to the main page app, if not it will show you the login page.

现在的问题是当用户在登录页面区域内时,他点击返回,他将进入登录"页面,然后重定向回主页,因为他已经登录了.

now the problem is when the user is inside the logged page area, and he clicks back he will get to the "login" page and than redirected back to the main page, as he is logged in already.

所以他陷入了无限循环.

So he is stuck in an infinite loop.

如何从历史记录中删除登录页面.

how can I remove the login page from the history.

就像在 android "android 从历史堆栈中删除活动"

just like in android "android remove activity from history stack"

推荐答案

这里是解决方案!

简单地使用:

  $ionicHistory.nextViewOptions({
     disableBack: true
  });

登录功能示例:

$scope.login = function () {

Security.login($scope.cred.email, $scope.cred.password)
    .success(function(data) {
        Security.setUser(data.data[0]);
        $ionicHistory.nextViewOptions({
            disableBack: true
        });
        $state.go('posts', {}, {location: "replace", reload: true});
    }).error(function(data) {
        $scope.showAlert();
    });
};
 
精彩推荐
图片推荐