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 navigation if already on the URL
Browse files Browse the repository at this point in the history
  • Loading branch information
mhevery committed May 2, 2013
1 parent fd21c75 commit 4bd7bed
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/ng/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
});

Expand Down
13 changes: 13 additions & 0 deletions test/ng/locationSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 4bd7bed

Please sign in to comment.