Skip to content

Commit e4e6176

Browse files
Richard Collinscaitp
Richard Collins
authored andcommitted
Potential fix for angular#6162
1 parent acfcbdf commit e4e6176

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

@@ -642,6 +652,35 @@ function $LocationProvider(){
642652
absHref = urlResolve(absHref.animVal).href;
643653
}
644654

655+
// Make relative links work in HTML5 mode for legacy browsers (or at least IE8 & 9)
656+
// The href should be a regular url e.g. /link/somewhere or link/somewhere or ../somewhere or somewhere#anchor or http://example.com/somewhere
657+
if (LocationMode === LocationHashbangInHtml5Url) {
658+
// get the actual href attribute - see http://msdn.microsoft.com/en-us/library/ie/dd347148(v=vs.85).aspx
659+
// TODO check browser is in standards mode
660+
var href = elm[0].getAttribute('href');
661+
662+
if (href.indexOf('://' == -1)) { // Ignore absolute URLs
663+
if (href[0] == '/') {
664+
// absolute path - replace old path
665+
absHref = serverBase(absHref) + href;
666+
} else {
667+
// relative path - join with current path
668+
var stack = $location.path().split("/"),
669+
parts = href.split("/");
670+
stack.pop(); // remove top file
671+
for (var i=0; i<parts.length; i++) {
672+
if (parts[i] == ".")
673+
continue;
674+
else if (parts[i] == "..")
675+
stack.pop();
676+
else
677+
stack.push(parts[i]);
678+
}
679+
absHref = serverBase(absHref) + stack.join("/");
680+
}
681+
}
682+
}
683+
645684
var rewrittenUrl = $location.$$rewrite(absHref);
646685

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

0 commit comments

Comments
 (0)