mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
fix($location): back-button should fire $locationChangeStart
Before $locationChangeStart event is not broadcast when pressing the back-button on the browser. Closes #2109
This commit is contained in:
parent
f75a2b093f
commit
ac086ae616
2 changed files with 7 additions and 1 deletions
|
|
@ -577,6 +577,10 @@ function $LocationProvider(){
|
|||
// update $location when $browser url changes
|
||||
$browser.onUrlChange(function(newUrl) {
|
||||
if ($location.absUrl() != newUrl) {
|
||||
if ($rootScope.$broadcast('$locationChangeStart', newUrl, $location.absUrl()).defaultPrevented) {
|
||||
$browser.url($location.absUrl());
|
||||
return;
|
||||
}
|
||||
$rootScope.$evalAsync(function() {
|
||||
var oldUrl = $location.absUrl();
|
||||
|
||||
|
|
|
|||
|
|
@ -1216,7 +1216,7 @@ describe('$location', function() {
|
|||
expect($location.url()).toEqual('');
|
||||
|
||||
$rootScope.$on('$locationChangeStart', function(event, newUrl, oldUrl) {
|
||||
throw Error('there is no before when user enters URL directly to browser');
|
||||
$log.info('start', newUrl, oldUrl);
|
||||
});
|
||||
$rootScope.$on('$locationChangeSuccess', function(event, newUrl, oldUrl) {
|
||||
$log.info('after', newUrl, oldUrl);
|
||||
|
|
@ -1226,6 +1226,8 @@ describe('$location', function() {
|
|||
$browser.url('http://server/#/somePath');
|
||||
$browser.poll();
|
||||
|
||||
expect($log.info.logs.shift()).
|
||||
toEqual(['start', 'http://server/#/somePath', 'http://server/']);
|
||||
expect($log.info.logs.shift()).
|
||||
toEqual(['after', 'http://server/#/somePath', 'http://server/']);
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue