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

Commit a01e9af

Browse files
fix($location): strip off empty hash segments when comparing
The url is the same whether or not there is an empty `#` marker at the end. This prevents unwanted digest turns. Closes #9635
1 parent be60ee9 commit a01e9af

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/ng/location.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ function stripHash(url) {
6868
return index == -1 ? url : url.substr(0, index);
6969
}
7070

71+
function getHash(url) {
72+
var index = url.indexOf('#');
73+
return index===-1 ? '' : url.substr(index+1);
74+
}
75+
76+
function trimEmptyHash(url) {
77+
return url.replace(/#$/,'');
78+
}
79+
7180

7281
function stripFile(url) {
7382
return url.substr(0, stripHash(url).lastIndexOf('/') + 1);
@@ -847,10 +856,11 @@ function $LocationProvider() {
847856

848857
// update browser
849858
$rootScope.$watch(function $locationWatch() {
850-
var oldUrl = $browser.url();
859+
var oldUrl = trimEmptyHash($browser.url());
860+
var newUrl = trimEmptyHash($location.absUrl());
851861
var oldState = $browser.state();
852862
var currentReplace = $location.$$replace;
853-
var urlOrStateChanged = oldUrl !== $location.absUrl() ||
863+
var urlOrStateChanged = oldUrl !== newUrl ||
854864
($location.$$html5 && $sniffer.history && oldState !== $location.$$state);
855865

856866
if (initializing || urlOrStateChanged) {

0 commit comments

Comments
 (0)