Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ionic framework Can´;t在Ionic中禁用后退按钮(历史记录、缓存等)_Ionic Framework_Ionic View - Fatal编程技术网

Ionic framework Can´;t在Ionic中禁用后退按钮(历史记录、缓存等)

Ionic framework Can´;t在Ionic中禁用后退按钮(历史记录、缓存等),ionic-framework,ionic-view,Ionic Framework,Ionic View,我有一个应用程序,带有一个登录视图,用户需要将您的凭据放入该应用程序才能登录 这是我的index.html: <!DOCTYPE html> <html ng-app="starter"> <head> <meta charset="utf-8"> <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width

我有一个应用程序,带有一个登录视图,用户需要将您的凭据放入该应用程序才能登录

这是我的index.html:

<!DOCTYPE html>
<html ng-app="starter">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <title>Services for Partners</title>

    <link href="lib/ionic/css/ionicons.min.css" rel="stylesheet">
    <link href="lib/ionic/css/ionic.css" rel="stylesheet">
    <script src="lib/ionic/js/ionic.bundle.js"></script>

    <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
    <link href="css/ionic.app.css" rel="stylesheet">
    -->

    <!-- cordova script (this will be a 404 during development) -->
    <script src="cordova.js"></script>

    <!-- your app's css and js -->
    <script src="js/app.js"></script>
    <script src="js/controllers.js"></script>
    <script src="js/routes.js"></script>
    <script src="js/services.js"></script>

    <link href="css/app.css" rel="stylesheet">

  </head>
  <body>
    <div>
        <ion-nav-view animation="slide-right-left" cache-view="false"></ion-nav-view>
    </div>
    <div class="bar bar-footer bar-dark">
        <div>copyright</div>
    </div>    
  </body>
</html>
在这里,我们可以看到我正在使用几个命令来禁用离子历史记录

下面是我的services.js文件:

var starter = angular.module('starter.services', []);

starter.run(function($ionicPlatform,$state,$ionicHistory){

    $ionicPlatform.registerBackButtonAction(function (event) {
        if($state.current.name=="home"){
            navigator.app.exitApp();
        }
        else {
            $ionicHistory.backHistory();
        }
    }, 100);
});
这是我的route.js文件:

var starter = angular.module('starter.routes', []);

//Rotas do app
starter.config(['$stateProvider', '$urlRouterProvider', '$locationProvider', 
    function($stateProvider, $urlRouterProvider, $locationProvider) {

  $stateProvider //.state(...).state(...).state(...)

    //Login
    .state('login', {
      url: '/login',
      cache: false,
      templateUrl: 'templates/login.html',
      controller: 'loginCtrl'
    })

    //Novo Usuário
    .state('newuser', {
      url: '/newuser',
      cache: false,
      templateUrl: 'templates/newuser.html',
      controller: 'newUserCtrl'
    })

    //Esqueceu a senha
    .state('forgotpwd', {
      url: '/forgotpwd',
      cache: false,
      templateUrl: 'templates/forgotpwd.html',
      controller: 'forgotPwdCtrl'
    })

    //Sobre
    .state('about', {
      url: '/about',
      cache: false,
      templateUrl: 'templates/about.html',
      controller: 'aboutCtrl'
    })

    //Home
    .state('home', {
      url: '/home',
      cache: false,
      templateUrl: 'templates/home.html',
      controller: 'homeCtrl'
    });

  // if none of the above states are matched, use this as the fallback
  $urlRouterProvider.otherwise('/login');

}]);
在这里,我将所有路由配置为不缓存任何视图

在所有这些事情之后,什么也没发生。我的应用程序仍然允许我点击后退按钮(不是硬件按钮,而是软件按钮)。我正在索尼Z3智能手机上运行的“爱奥尼亚视图应用程序”上预览我的应用程序

因此,用户无需登录即可返回主页

如果用户在登录视图中单击后退按钮,我想退出应用程序。但是在所有这些配置之后,我仍然带着这个问题运行

我需要做什么

我已经更新了科尔多瓦和爱奥尼亚。这是一个bug还是有可能解决这个问题

谢谢。

你为什么不试试这个

///code to skip login page if logged in
.run(function ($rootScope, $state) {
    // Check login session
    $rootScope.$on('$stateChangeStart', function (event, next, current) {

        if(condition to check that you are logged in..maybe store token in localstorage and heck){
           if (next.name === "login") {
              event.preventDefault();
              $state.go('home');
            }

        }


    });
})
用于后退按钮操作

 .run(['$rootScope', '$ionicPlatform','$state', '$ionicHistory',
        function($rootScope, $ionicPlatform,$state, $ionicHistory){
      $ionicPlatform.registerBackButtonAction(function(e){

     if ($state.current.name == 'home') {
      ionic.Platform.exitApp();

    }
    else if ($ionicHistory.backView() ) {
      $ionicHistory.goBack();
    }
    e.preventDefault();
    return false;
  },101);

}])

在登录html中,您可以设置
,有关更多信息,请参阅本文档。注销后,您应该使用$IonichStory清除应用程序的历史记录。请参阅清除历史记录的链接。
///code to skip login page if logged in
.run(function ($rootScope, $state) {
    // Check login session
    $rootScope.$on('$stateChangeStart', function (event, next, current) {

        if(condition to check that you are logged in..maybe store token in localstorage and heck){
           if (next.name === "login") {
              event.preventDefault();
              $state.go('home');
            }

        }


    });
})
 .run(['$rootScope', '$ionicPlatform','$state', '$ionicHistory',
        function($rootScope, $ionicPlatform,$state, $ionicHistory){
      $ionicPlatform.registerBackButtonAction(function(e){

     if ($state.current.name == 'home') {
      ionic.Platform.exitApp();

    }
    else if ($ionicHistory.backView() ) {
      $ionicHistory.goBack();
    }
    e.preventDefault();
    return false;
  },101);

}])