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

Commit ac086ae

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 f75a2b0 commit ac086ae

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
@@ -577,6 +577,10 @@ function $LocationProvider(){
577577
// update $location when $browser url changes
578578
$browser.onUrlChange(function(newUrl) {
579579
if ($location.absUrl() != newUrl) {
580+
if ($rootScope.$broadcast('$locationChangeStart', newUrl, $location.absUrl()).defaultPrevented) {
581+
$browser.url($location.absUrl());
582+
return;
583+
}
580584
$rootScope.$evalAsync(function() {
581585
var oldUrl = $location.absUrl();
582586

test/ng/locationSpec.js

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

12181218
$rootScope.$on('$locationChangeStart', function(event, newUrl, oldUrl) {
1219-
throw Error('there is no before when user enters URL directly to browser');
1219+
$log.info('start', newUrl, oldUrl);
12201220
});
12211221
$rootScope.$on('$locationChangeSuccess', function(event, newUrl, oldUrl) {
12221222
$log.info('after', newUrl, oldUrl);
@@ -1226,6 +1226,8 @@ describe('$location', function() {
12261226
$browser.url('http://server/#/somePath');
12271227
$browser.poll();
12281228

1229+
expect($log.info.logs.shift()).
1230+
toEqual(['start', 'http://server/#/somePath', 'http://server/']);
12291231
expect($log.info.logs.shift()).
12301232
toEqual(['after', 'http://server/#/somePath', 'http://server/']);
12311233
})

0 commit comments

Comments
 (0)