title: Can´t disable Back Button (history, cache, ...) in Ionic
body: <p>I have an app, with a login view that the user needs to put your credentials to login.</p>
  
  <p>This is my index.html:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html ng-app="starter"&gt;
    &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"&gt;
      &lt;title&gt;Services for Partners&lt;/title&gt;
  
      &lt;link href="lib/ionic/css/ionicons.min.css" rel="stylesheet"&gt;
      &lt;link href="lib/ionic/css/ionic.css" rel="stylesheet"&gt;
      &lt;script src="lib/ionic/js/ionic.bundle.js"&gt;&lt;/script&gt;
  
      &lt;!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
      &lt;link href="css/ionic.app.css" rel="stylesheet"&gt;
      --&gt;
  
      &lt;!-- cordova script (this will be a 404 during development) --&gt;
      &lt;script src="cordova.js"&gt;&lt;/script&gt;
  
      &lt;!-- your app's css and js --&gt;
      &lt;script src="js/app.js"&gt;&lt;/script&gt;
      &lt;script src="js/controllers.js"&gt;&lt;/script&gt;
      &lt;script src="js/routes.js"&gt;&lt;/script&gt;
      &lt;script src="js/services.js"&gt;&lt;/script&gt;
  
      &lt;link href="css/app.css" rel="stylesheet"&gt;
  
    &lt;/head&gt;
    &lt;body&gt;
      &lt;div&gt;
          &lt;ion-nav-view animation="slide-right-left" cache-view="false"&gt;&lt;/ion-nav-view&gt;
      &lt;/div&gt;
      &lt;div class="bar bar-footer bar-dark"&gt;
          &lt;div&gt;copyright&lt;/div&gt;
      &lt;/div&gt;    
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>In my index.html I am using the attribute cache-view="false".</p>
  
  <p>After the user has logged in, he is redirect to home view.</p>
  
  <p>Here is part of my home view:</p>
  
  <pre><code>&lt;ion-view title="home" ng-controller="homeCtrl"&gt;
      &lt;div class="bar bar-header bar-dark"&gt;
          &lt;button class="button button-icon icon ion-gear-b"&gt;&lt;/button&gt;
          &lt;button class="button button-icon icon ion-android-close" ng-click="closeApp()"&gt;&lt;/button&gt;
      &lt;/div&gt;
      &lt;ion-content overflow-scroll="true" padding="true" scroll="true" class="has-header has-footer"&gt;
          &lt;!--&lt;div class="spacer" style="width: 300px; height: 15px;"&gt;&lt;/div&gt;--&gt;
          &lt;div style="text-align:center;"&gt;
              &lt;img src="img/logo.png" class="logo-pequena"&gt;
          &lt;/div&gt;        
          &lt;div&gt;
  </code></pre>
  
  <p>In the home view, I have a button to log out, calling a method closeApp().</p>
  
  <p>Here is my home controller, with my closeApp() method:</p>
  
  <pre><code>starter.controller('homeCtrl', ['$scope', '$state', '$ionicHistory', function($scope, $state, $ionicHistory) {
  
      $scope.closeApp = function() {
  
          //Remove todos as infos do usuário do localStorage
          localStorage.clear();
  
          $ionicHistory.clearHistory();
          $ionicHistory.clearCache();
          $ionicHistory.nextViewOptions({
              historyRoot: true,
              disableAnimate: true,
              disableBack: true
          });
  
          $state.go('login');
      }
  
  }]);
  </code></pre>
  
  <p>Here we can see that I am using several commands to disable ionic history.</p>
  
  <p>Below, is my services.js file:</p>
  
  <pre><code>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);
  });
  </code></pre>
  
  <p>Here is my route.js file:</p>
  
  <pre><code>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');
  
  }]);
  </code></pre>
  
  <p>Here I have configured all routes to not caching any view.</p>
  
  <p>After all those stuffs nothing happens. My app still permits me click on back button (not a hardware button, but the software button). I am previewing my app on "Ionic View App" running in my Sony Z3 smartphone.</p>
  
  <p>So, the user can go back to home page, without logging in. </p>
  
  <p>I want to exit app if the user clicks the back button at login view. But after all those configurations, I am still running with this trouble.</p>
  
  <p>What I need to do ?</p>
  
  <p>I have already updated cordova and ionic. Is it a bug or is it possible to resolve this issue ?</p>
  
  <p>Thanks.</p>