Remove page from history, so “back” will work properly

拜拜、爱过 提交于 2019-11-28 19:22:32
Tzook Bar Noy

here is the solution!

simply use:

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

example for login function:

$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();
    });
};

For a pure AngularJS way to accomplish this (rather than ionic or javascript in the other answers), use the $location service's replace() method (documentation) :

Use $location.url('/newpath'); or $location.path('/newpath'); as you normally would to do the redirection in angular. And then just add $location.replace(); right after it. Or you can chain the commands like this:

$location.url('/newpath').replace();
Phil

Quick search: https://stackoverflow.com/a/8969975/185672

Top answer:

Instead of using window.location = url; to redirect,

try window.location.replace(url);.

after using replace() the current page will not be saved in session history, meaning the user won't be able to use the Back button to navigate to it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!