这是Angular的解决方案。
myApp.run(function($rootScope, $route, $location){ //Bind the `$locationChangeSuccess` event on the rootScope, so that we dont need to //bind in induvidual controllers. $rootScope.$on('$locationChangeSuccess', function() { $rootScope.actualLocation = $location.path(); }); $rootScope.$watch(function () {return $location.path()}, function (newLocation, oldLocation) { if($rootScope.actualLocation === newLocation) { alert('Why did you use history back?'); } });});我正在使用运行块来启动它。首先,我将实际位置存储在$ rootScope.actualLocation中,然后侦听$
locationChangeSuccess,并在发生这种情况时使用新值更新ActualLocation。
在$ rootScope中,我监视位置路径中的更改,以及新位置是否与previousLocation相等,这是因为未触发$
locationChangeSuccess,这意味着用户已使用了历史记录。



