From 6d7e7fdea6c3d6551ff40c150aa42e1375d2cb5f Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Wed, 11 Apr 2012 23:46:23 -0700 Subject: 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 --- src/ng/location.js | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'src/ng/location.js') 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 -- cgit v1.2.3