2

I am using ng-routing in application in angularjs. I have my own back button. I want to go back to previous page from where I have redirected to this page? Kindly help me?

  • Refer the following link : 1) https://stackoverflow.com/questions/42409803/browser-back-button-redirecting-to-previous-page-and-appending-the-route-to-url 2) https://stackoverflow.com/questions/15175429/angularjs-getting-previous-route-path – Prashant Jul 05 '17 at 06:02

2 Answers2

3

You can use history.back() on click of your back button. this will redirect to your previous page using browser's history.

Tejinder Singh
  • 1,070
  • 2
  • 8
  • 24
1

A simple directive for that

app.directive('historyBackward', ['$window', function($window) {
    return {
        restrict: 'A',
        link: function(scope, elem, attrs) {
            elem.bind('click', function() {
                $window.history.back();
            });
        }
    };
}]);

In your HTML

<button history-backward>back</button>

Sibiraj
  • 4,486
  • 7
  • 33
  • 57