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

Commit

Permalink
fix($location): prevent page reload if initial url has empty hash at …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
dtritus authored and petebacondarwin committed Feb 4, 2015
1 parent 7f50e97 commit 4b3a590
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ng/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,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

0 comments on commit 4b3a590

Please sign in to comment.