From bc71e7b8c909483909a9453138ac934657f041aa Mon Sep 17 00:00:00 2001 From: Richard Collins Date: Mon, 24 Feb 2014 11:44:52 +1300 Subject: [PATCH 1/2] Potential fix for #6162 --- src/ng/location.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/ng/location.js b/src/ng/location.js index c4b7545d78f0..131917b88069 100644 --- a/src/ng/location.js +++ b/src/ng/location.js @@ -268,6 +268,16 @@ function LocationHashbangInHtml5Url(appBase, hashPrefix) { return appBaseNoFile; } }; + + this.$$compose = function() { + var search = toKeyValue(this.$$search), + hash = this.$$hash ? '#' + encodeUriSegment(this.$$hash) : ''; + + this.$$url = encodePath(this.$$path) + (search ? '?' + search : '') + hash; + // include hashPrefix in $$absUrl when $$url is empty so IE8 & 9 do not reload page because of removal of '#' + this.$$absUrl = appBase + hashPrefix + this.$$url; + }; + } @@ -621,6 +631,35 @@ function $LocationProvider(){ absHref = urlResolve(absHref.animVal).href; } + // Make relative links work in HTML5 mode for legacy browsers (or at least IE8 & 9) + // The href should be a regular url e.g. /link/somewhere or link/somewhere or ../somewhere or somewhere#anchor or http://example.com/somewhere + if (LocationMode === LocationHashbangInHtml5Url) { + // get the actual href attribute - see http://msdn.microsoft.com/en-us/library/ie/dd347148(v=vs.85).aspx + // TODO check browser is in standards mode + var href = elm[0].getAttribute('href'); + + if (href.indexOf('://' == -1)) { // Ignore absolute URLs + if (href[0] == '/') { + // absolute path - replace old path + absHref = serverBase(absHref) + href; + } else { + // relative path - join with current path + var stack = $location.path().split("/"), + parts = href.split("/"); + stack.pop(); // remove top file + for (var i=0; i Date: Mon, 17 Mar 2014 12:03:44 +1300 Subject: [PATCH 2/2] Parse anchors in IE9 --- src/ng/location.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ng/location.js b/src/ng/location.js index 131917b88069..6f837993a3b3 100644 --- a/src/ng/location.js +++ b/src/ng/location.js @@ -642,6 +642,9 @@ function $LocationProvider(){ if (href[0] == '/') { // absolute path - replace old path absHref = serverBase(absHref) + href; + } else if (href[0] == '#') { + // local anchor + absHref = serverBase(absHref) + $location.path() + href } else { // relative path - join with current path var stack = $location.path().split("/"),