Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit dc9a580

Browse files
quazziepetebacondarwin
authored andcommitted
fix($location): back-button should fire $locationChangeStart
Before $locationChangeStart event is not broadcast when pressing the back-button on the browser. Closes #2109
1 parent 660605b commit dc9a580

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/ng/location.js

+4
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,10 @@ function $LocationProvider(){
546546
// update $location when $browser url changes
547547
$browser.onUrlChange(function(newUrl) {
548548
if ($location.absUrl() != newUrl) {
549+
if ($rootScope.$broadcast('$locationChangeStart', newUrl, $location.absUrl()).defaultPrevented) {
550+
$browser.url($location.absUrl());
551+
return;
552+
}
549553
$rootScope.$evalAsync(function() {
550554
var oldUrl = $location.absUrl();
551555

test/ng/locationSpec.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,7 @@ describe('$location', function() {
12371237
expect($location.url()).toEqual('');
12381238

12391239
$rootScope.$on('$locationChangeStart', function(event, newUrl, oldUrl) {
1240-
throw Error('there is no before when user enters URL directly to browser');
1240+
$log.info('start', newUrl, oldUrl);
12411241
});
12421242
$rootScope.$on('$locationChangeSuccess', function(event, newUrl, oldUrl) {
12431243
$log.info('after', newUrl, oldUrl);
@@ -1247,6 +1247,8 @@ describe('$location', function() {
12471247
$browser.url('http://server/#/somePath');
12481248
$browser.poll();
12491249

1250+
expect($log.info.logs.shift()).
1251+
toEqual(['start', 'http://server/#/somePath', 'http://server/']);
12501252
expect($log.info.logs.shift()).
12511253
toEqual(['after', 'http://server/#/somePath', 'http://server/']);
12521254
})

0 commit comments

Comments
 (0)