title: AngularJS redirect a route only on browser's back button
body: <p>In my AngularJS application I'm redirecting the <code>route</code> to a specific page when the user isn't logged. To do that I'm using a variable on <code>$rootScope</code>. </p>
  
  <p>Now I would like to prevent the browser's back button when the user is logged.  I would like to redirect it to a specific page (the <code>registration</code> view). The problem is I don't know if there's a <em>back button event</em>.</p>
  
  <p>My code is:</p>
  
  <pre><code> angular.module('myApp',[...]
  //Route configurations
  }])
  .run(function($rootScope, $location){
                 $rootScope.$on('$routeChangeStart', function(event, next, current){
                     if(!$rootScope.loggedUser) { 
                         $location.path('/register');
                     }
                 });
                 $rootScope.$on('$locationChangeStart', function(event, next, current){
                     console.log("Current: " + current);
                     console.log("Next: " + next);
                 });
             });
  </code></pre>
  
  <p>So on <code>$locationChangeStart</code> I would write a pseudocode like:</p>
  
  <pre><code>if (event == backButton){
       $location.path('/register');
  }
  </code></pre>
  
  <p>Is it possible?</p>
  
  <p>A naive solution would be writing a function that checks if <code>next</code> and <code>current</code> are in the wrong order, detecting if the user is <em>going back</em>.</p>
  
  <p>There are other solutions? I'm approaching the problem in a wrong way?</p>