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

fix($location): ensure $locationChangeStart broadcast during $digest #5580

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions src/ng/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -656,21 +656,30 @@ function $LocationProvider(){
$browser.url($location.absUrl(), true);
}

function browserUrlChange(newUrl) {
if ($rootScope.$broadcast('$locationChangeStart', newUrl,
$location.absUrl()).defaultPrevented) {
$browser.url($location.absUrl());
return;
}
$rootScope.$evalAsync(function() {
var oldUrl = $location.absUrl();

$location.$$parse(newUrl);
afterLocationChange(oldUrl);
});
}

// 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;
if ($rootScope.$$phase) {
browserUrlChange(newUrl);
} else {
$rootScope.$apply(function() {
browserUrlChange(newUrl);
});
}
$rootScope.$evalAsync(function() {
var oldUrl = $location.absUrl();

$location.$$parse(newUrl);
afterLocationChange(oldUrl);
});
if (!$rootScope.$$phase) $rootScope.$digest();
}
});

Expand Down