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

fix($location): prevent page reload if url has empty hash at the end #10960

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/ng/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ function $LocationProvider() {


// rewrite hashbang url <> html5 url
if ($location.absUrl() != initialUrl) {
if (trimEmptyHash($location.absUrl()) != trimEmptyHash(initialUrl)) {
$browser.url($location.absUrl(), true);
}

Expand Down
10 changes: 10 additions & 0 deletions test/ng/locationSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,16 @@ describe('$location', function() {
}));
});

describe('rewrite hashbang url <> html5 url', function() {
beforeEach(initService({html5Mode: true, supportHistory: true}));
beforeEach(inject(initBrowser({url:'http://new.com/#', basePath: '/'})));

it('should not replace browser url if only the empty hash fragment is cleared', inject(function($browser, $location) {
expect($browser.url()).toBe('http://new.com/#');
expect($location.absUrl()).toBe('http://new.com/');
}));
});

describe('wiring', function() {

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