aboutsummaryrefslogtreecommitdiffstats
path: root/src/ng/location.js
diff options
context:
space:
mode:
authorIgor Minar2012-04-11 23:46:23 -0700
committerIgor Minar2012-04-12 02:36:03 -0700
commit6d7e7fdea6c3d6551ff40c150aa42e1375d2cb5f (patch)
tree47cc1d0f24f424df8f964595ee98a4c6b30bb981 /src/ng/location.js
parentdf72852f3496d7640bb4f70837338e464b7ed69f (diff)
downloadangular.js-6d7e7fdea6c3d6551ff40c150aa42e1375d2cb5f.tar.bz2
fix($location): properly rewrite urls in html5 mode with base url set
previously we were doing all kinds of checks to see if we should rewrite the url or not and we were missing many scenarios. not any more. with this change, we rewrite the url unless: - the href is not set - link has target attribute - the absolute url of the link doesn't match the absolute prefix for all urls in our app This also means that ng-ext-link attribute which we previously used to distinguish external links from app links is not necessary any more. apps can just set target=_self to prevent rewriting. BREAKING CHANGE: ng-ext-link directive was removed because it's unnecessary apps that relied on ng-ext-link should simply replace it with target=_self
Diffstat (limited to 'src/ng/location.js')
-rw-r--r--src/ng/location.js22
1 files changed, 8 insertions, 14 deletions
diff --git a/src/ng/location.js b/src/ng/location.js
index 9feee5ad..575feb7e 100644
--- a/src/ng/location.js
+++ b/src/ng/location.js
@@ -500,22 +500,16 @@ function $LocationProvider(){
elm = elm.parent();
}
- var href = elm.attr('href');
- if (!href || isDefined(elm.attr('ng-ext-link')) || elm.attr('target')) return;
+ var absHref = elm.prop('href');
- // link to different base path
- if (href[0] === '/' && href.indexOf(pathPrefix) !== 0) return;
-
- // remove same domain from full url links (IE7 always returns full hrefs)
- href = href.replace(absUrlPrefix, '');
-
- // link to different domain (or base path)
- if (href.substr(0, 4) == 'http') return;
-
- // remove pathPrefix from absolute links
- href = href.indexOf(pathPrefix) === 0 ? href.substr(pathPrefix.length) : href;
+ if (!absHref ||
+ elm.attr('target') ||
+ absHref.indexOf(absUrlPrefix) !== 0) { // link to different domain or base path
+ return;
+ }
- currentUrl.url(href);
+ // update location with href without the prefix
+ currentUrl.url(absHref.substr(absUrlPrefix.length));
$rootScope.$apply();
event.preventDefault();
// hack to work around FF6 bug 684208 when scenario runner clicks on links