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

Commit 382efe4

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 965dab2 commit 382efe4

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Diff for: src/ng/location.js

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

71+
function trimEmptyHash(url) {
72+
return url.replace(/#$/,'');
73+
}
74+
7175

7276
function stripFile(url) {
7377
return url.substr(0, stripHash(url).lastIndexOf('/') + 1);
@@ -847,10 +851,11 @@ function $LocationProvider() {
847851

848852
// update browser
849853
$rootScope.$watch(function $locationWatch() {
850-
var oldUrl = $browser.url();
854+
var oldUrl = trimEmptyHash($browser.url());
855+
var newUrl = trimEmptyHash($location.absUrl());
851856
var oldState = $browser.state();
852857
var currentReplace = $location.$$replace;
853-
var urlOrStateChanged = oldUrl !== $location.absUrl() ||
858+
var urlOrStateChanged = oldUrl !== newUrl ||
854859
($location.$$html5 && $sniffer.history && oldState !== $location.$$state);
855860

856861
if (initializing || urlOrStateChanged) {

0 commit comments

Comments
 (0)