Akash Vashista
Akash Vashista

Reputation: 55

How to redirect to previous page using own back button?

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?

Upvotes: 2

Views: 6246

Answers (2)

Sibiraj
Sibiraj

Reputation: 4756

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>

Upvotes: 1

Tejinder Singh
Tejinder Singh

Reputation: 1120

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

Upvotes: 3

Related Questions