Skip to content

Commit 25467d5

Browse files
Richard Collinscaitp
Richard Collins
authored andcommitted
Parse anchors in IE9
1 parent 2a8ff31 commit 25467d5

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/ng/location.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ function LocationHashbangInHtml5Url(appBase, hashPrefix) {
274274
hash = this.$$hash ? '#' + encodeUriSegment(this.$$hash) : '';
275275

276276
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 '#'
277+
// include hashPrefix in $$absUrl when $$url is empty so IE8 & 9 do not reload page because of removal of '#'
278278
this.$$absUrl = appBase + hashPrefix + this.$$url;
279279
};
280280

@@ -632,18 +632,21 @@ function $LocationProvider(){
632632
}
633633

634634
// 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
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
636636
if (LocationMode === LocationHashbangInHtml5Url) {
637637
// get the actual href attribute - see http://msdn.microsoft.com/en-us/library/ie/dd347148(v=vs.85).aspx
638638
// TODO check browser is in standards mode
639639
var href = elm[0].getAttribute('href');
640-
641-
if (href.indexOf('://' == -1)) { // Ignore absolute URLs
640+
641+
if (href.indexOf('://' == -1)) { // Ignore absolute URLs
642642
if (href[0] == '/') {
643643
// absolute path - replace old path
644644
absHref = serverBase(absHref) + href;
645+
} else if (href[0] == '#') {
646+
// local anchor
647+
absHref = serverBase(absHref) + $location.path() + href;
645648
} else {
646-
// relative path - join with current path
649+
// relative path - join with current path
647650
var stack = $location.path().split("/"),
648651
parts = href.split("/");
649652
stack.pop(); // remove top file
@@ -657,7 +660,7 @@ function $LocationProvider(){
657660
}
658661
absHref = serverBase(absHref) + stack.join("/");
659662
}
660-
}
663+
}
661664
}
662665

663666
var rewrittenUrl = $location.$$rewrite(absHref);

0 commit comments

Comments
 (0)