@@ -268,6 +268,16 @@ function LocationHashbangInHtml5Url(appBase, hashPrefix) {
268
268
return appBaseNoFile ;
269
269
}
270
270
} ;
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
+
271
281
}
272
282
273
283
@@ -621,6 +631,35 @@ function $LocationProvider(){
621
631
absHref = urlResolve ( absHref . animVal ) . href ;
622
632
}
623
633
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
+
624
663
var rewrittenUrl = $location . $$rewrite ( absHref ) ;
625
664
626
665
if ( absHref && ! elm . attr ( 'target' ) && rewrittenUrl && ! event . isDefaultPrevented ( ) ) {
0 commit comments