title: Infinite loop during window.history.back in Angular JS
body: <p>I'm building the website and I'm having an issue regarding window.history.back.</p>
  
  <p>I used window.history.back() for 'Back' button, expecting it to function as the back button on browser.</p>
  
  <p>When I get to press 'Back' button twice in a row, I get to infinite loop between two pages.</p>
  
  <p>For example, let's say there are three pages, A, B, and C.</p>
  
  <p>Page B can be accessed only through Page A.</p>
  
  <p>Page C can be accessed only through Page B.</p>
  
  <p>'Back' button is in a bar, implemented as a separate directive. Both Page B and Page C use this directive.</p>
  
  <p>When I get to Page C and press back button, I get directed to Page B. If I click back button again in Page B, I get directed back to Page C. Afterward, I press back button on Page C, I get into infinite loop between Page B and C.</p>
  
  <p>How can I solve this problem?</p>
  
  <p>Code underneath is a directive for bar </p>
  
  <pre><code>.directive('BarBack', [function() {
      return {
          replace: false,
          restrict: 'E',
          template: '&lt;bar-button et-icon="keyboard_arrow_left" on-click="ctrl.onClick()"&gt;{{ "BACK" | translate }}&lt;/bar-button&gt;',
          transclude: false,
          scope: {
              icon: '@',
              stringId: '@',
              state: '@'
          },
          controllerAs: 'ctrl',
          controller: ['$window', function($window) {
              var ctrl = this;
  
              ctrl.onClick = function() {
                  $window.history.back();
              }
          }]
      }
  }])
  </code></pre>
  
  <p>I cannot do hard-coded to specific location.</p>
  
  <p>Thank you in advance.</p>