From fb98bb26ce5102290de3b531f8913fc64f20136e Mon Sep 17 00:00:00 2001 From: dtritus Date: Wed, 4 Feb 2015 11:05:23 +0200 Subject: [PATCH] fix($location): prevent page reload if url has empty hash at the end If initial url has empty hash at the end, $location replaces it with url without hash causing page reload Closes #10397 --- src/ng/location.js | 2 +- test/ng/locationSpec.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/ng/location.js b/src/ng/location.js index fbec715c9fbb..dfe22cd000cd 100644 --- a/src/ng/location.js +++ b/src/ng/location.js @@ -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); } diff --git a/test/ng/locationSpec.js b/test/ng/locationSpec.js index 0f7491db215e..de0561d0c16f 100644 --- a/test/ng/locationSpec.js +++ b/test/ng/locationSpec.js @@ -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}));