Reputation: 48
I need to disable browser back button. Is there any way to detect browser back event using angularjs?
Upvotes: 0
Views: 1953
Reputation: 556
Why do you want to do this? If you use the angular router it should handle back and forward button clicks and go to the appropriate routes and therefore show the correct pages.
If there is a page you don't want the user to be able to go back to, you can call $location.replace()
to replace the current history item instead of adding new history. For example
// current page is /cat/new, a link on this page calls newCat('fluffy')
scope.newCat = function createCat(catzName) {
scope.cat = { name: catzName }
// go to the details page for that cat
$location.path('/cat/' + catzName);
// don't let the user go back to /cat/new
$location.replace();
}
Upvotes: 1