Skip to content

Commit 2a8ff31

Browse files
Richard Collinscaitp
Richard Collins
authored andcommitted
Potential fix for angular#6162
1 parent ff5cf73 commit 2a8ff31

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/ng/location.js

+39
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,16 @@ function LocationHashbangInHtml5Url(appBase, hashPrefix) {
268268
return appBaseNoFile;
269269
}
270270
};
271+
272+
this.$$compose = function() {
273+
var search = toKeyValue(this.$$search),
274+
hash = this.$$hash ? '#' + encodeUriSegment(this.$$hash) : '';
275+
276+
this.$$url = encodePath(this.$$path) + (search ? '?' + search : '') + hash;
277+
// include hashPrefix in $$absUrl when $$url is empty so IE8 & 9 do not reload page because of removal of '#'
278+
this.$$absUrl = appBase + hashPrefix + this.$$url;
279+
};
280+
271281
}
272282

273283

@@ -621,6 +631,35 @@ function $LocationProvider(){
621631
absHref = urlResolve(absHref.animVal).href;
622632
}
623633

634+
// Make relative links work in HTML5 mode for legacy browsers (or at least IE8 & 9)
635+
// The href should be a regular url e.g. /link/somewhere or link/somewhere or ../somewhere or somewhere#anchor or http://example.com/somewhere
636+
if (LocationMode === LocationHashbangInHtml5Url) {
637+
// get the actual href attribute - see http://msdn.microsoft.com/en-us/library/ie/dd347148(v=vs.85).aspx
638+
// TODO check browser is in standards mode
639+
var href = elm[0].getAttribute('href');
640+
641+
if (href.indexOf('://' == -1)) { // Ignore absolute URLs
642+
if (href[0] == '/') {
643+
// absolute path - replace old path
644+
absHref = serverBase(absHref) + href;
645+
} else {
646+
// relative path - join with current path
647+
var stack = $location.path().split("/"),
648+
parts = href.split("/");
649+
stack.pop(); // remove top file
650+
for (var i=0; i<parts.length; i++) {
651+
if (parts[i] == ".")
652+
continue;
653+
else if (parts[i] == "..")
654+
stack.pop();
655+
else
656+
stack.push(parts[i]);
657+
}
658+
absHref = serverBase(absHref) + stack.join("/");
659+
}
660+
}
661+
}
662+
624663
var rewrittenUrl = $location.$$rewrite(absHref);
625664

626665
if (absHref && !elm.attr('target') && rewrittenUrl && !event.isDefaultPrevented()) {

0 commit comments

Comments
 (0)