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

Commit 4b3a590

Browse files
dtrituspetebacondarwin
authored andcommitted
fix($location): prevent page reload if initial url has empty hash at the end
If initial url has empty hash at the end, $location replaces it with url without hash causing an unwanted page reload. Closes #10397 Closes #10960
1 parent 7f50e97 commit 4b3a590

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/ng/location.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ function $LocationProvider() {
879879

880880

881881
// rewrite hashbang url <> html5 url
882-
if ($location.absUrl() != initialUrl) {
882+
if (trimEmptyHash($location.absUrl()) != trimEmptyHash(initialUrl)) {
883883
$browser.url($location.absUrl(), true);
884884
}
885885

test/ng/locationSpec.js

+10
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,16 @@ describe('$location', function() {
673673
}));
674674
});
675675

676+
describe('rewrite hashbang url <> html5 url', function() {
677+
beforeEach(initService({html5Mode: true, supportHistory: true}));
678+
beforeEach(inject(initBrowser({url:'http://new.com/#', basePath: '/'})));
679+
680+
it('should not replace browser url if only the empty hash fragment is cleared', inject(function($browser, $location) {
681+
expect($browser.url()).toBe('http://new.com/#');
682+
expect($location.absUrl()).toBe('http://new.com/');
683+
}));
684+
});
685+
676686
describe('wiring', function() {
677687

678688
beforeEach(initService({html5Mode:false,hashPrefix: '!',supportHistory: true}));

0 commit comments

Comments
 (0)