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

Commit df66e9d

Browse files
fix($browser): use location.hash if only the hash has changed
Closes #9635
1 parent 0f7bcfd commit df66e9d

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/ng/browser.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
'use strict';
22
/* global stripHash: true */
33

4+
function getHash(url) {
5+
var index = url.indexOf('#');
6+
return index === -1 ? '' : url.substr(index + 1);
7+
}
8+
49
/**
510
* ! This is a private undocumented service !
611
*
@@ -191,8 +196,10 @@ function Browser(window, document, $log, $sniffer) {
191196
}
192197
if (replace) {
193198
location.replace(url);
194-
} else {
199+
} else if (!sameBase) {
195200
location.href = url;
201+
} else {
202+
location.hash = getHash(url);
196203
}
197204
}
198205
return self;

test/ng/browserSpecs.js

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
/* global getHash:true, stripHash:true */
4+
35
var historyEntriesLength;
46
var sniffer = {};
57

@@ -51,6 +53,12 @@ function MockWindow(options) {
5153
mockWindow.history.state = null;
5254
historyEntriesLength++;
5355
},
56+
get hash() {
57+
return getHash(locationHref);
58+
},
59+
set hash(value) {
60+
locationHref = stripHash(locationHref) + '#' + value;
61+
},
5462
replace: function(url) {
5563
locationHref = url;
5664
mockWindow.history.state = null;

0 commit comments

Comments
 (0)