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

Commit 4bd7bed

Browse files
committed
fix($location): prevent navigation if already on the URL
1 parent fd21c75 commit 4bd7bed

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/ng/location.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -528,12 +528,14 @@ function $LocationProvider(){
528528
rewrittenUrl = $location.$$rewrite(absHref);
529529

530530
if (absHref && !elm.attr('target') && rewrittenUrl) {
531-
// update location manually
532-
$location.$$parse(rewrittenUrl);
533-
$rootScope.$apply();
534531
event.preventDefault();
535-
// hack to work around FF6 bug 684208 when scenario runner clicks on links
536-
window.angular['ff-684208-preventDefault'] = true;
532+
if (rewrittenUrl != initialUrl) {
533+
// update location manually
534+
$location.$$parse(rewrittenUrl);
535+
$rootScope.$apply();
536+
// hack to work around FF6 bug 684208 when scenario runner clicks on links
537+
window.angular['ff-684208-preventDefault'] = true;
538+
}
537539
}
538540
});
539541

test/ng/locationSpec.js

+13
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,19 @@ describe('$location', function() {
819819
});
820820

821821

822+
it('should do nothing if already on the same URL', function() {
823+
configureService('/base/', true, true);
824+
inject(
825+
initBrowser(),
826+
initLocation(),
827+
function($browser) {
828+
browserTrigger(link, 'click');
829+
expectNoRewrite($browser, 'http://host.com/base/');
830+
}
831+
);
832+
});
833+
834+
822835
it('should rewrite abs link to new url when history enabled on new browser', function() {
823836
configureService('/base/link?a#b', true, true);
824837
inject(

0 commit comments

Comments
 (0)