From 4bd7bedf48c0c1ebb62f6bd8c85e8ea00f94502b Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 2 May 2013 14:12:48 -0400 Subject: fix($location): prevent navigation if already on the URL --- src/ng/location.js | 12 +++++++----- test/ng/locationSpec.js | 13 +++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/ng/location.js b/src/ng/location.js index b6d14e1a..1a7f4208 100644 --- a/src/ng/location.js +++ b/src/ng/location.js @@ -528,12 +528,14 @@ function $LocationProvider(){ rewrittenUrl = $location.$$rewrite(absHref); if (absHref && !elm.attr('target') && rewrittenUrl) { - // update location manually - $location.$$parse(rewrittenUrl); - $rootScope.$apply(); event.preventDefault(); - // hack to work around FF6 bug 684208 when scenario runner clicks on links - window.angular['ff-684208-preventDefault'] = true; + if (rewrittenUrl != initialUrl) { + // update location manually + $location.$$parse(rewrittenUrl); + $rootScope.$apply(); + // hack to work around FF6 bug 684208 when scenario runner clicks on links + window.angular['ff-684208-preventDefault'] = true; + } } }); diff --git a/test/ng/locationSpec.js b/test/ng/locationSpec.js index fb828044..3588150d 100644 --- a/test/ng/locationSpec.js +++ b/test/ng/locationSpec.js @@ -819,6 +819,19 @@ describe('$location', function() { }); + it('should do nothing if already on the same URL', function() { + configureService('/base/', true, true); + inject( + initBrowser(), + initLocation(), + function($browser) { + browserTrigger(link, 'click'); + expectNoRewrite($browser, 'http://host.com/base/'); + } + ); + }); + + it('should rewrite abs link to new url when history enabled on new browser', function() { configureService('/base/link?a#b', true, true); inject( -- cgit v1.2.3