@@ -476,12 +476,14 @@ function $LocationProvider(){
476476 this . $get = [ '$rootScope' , '$browser' , '$sniffer' , '$rootElement' ,
477477 function ( $rootScope , $browser , $sniffer , $rootElement ) {
478478 var $location ,
479- basePath = $browser . baseHref ( ) || '/' ,
480- pathPrefix = pathPrefixFromBase ( basePath ) ,
479+ basePath ,
480+ pathPrefix ,
481481 initUrl = $browser . url ( ) ,
482482 absUrlPrefix ;
483483
484484 if ( html5Mode ) {
485+ basePath = $browser . baseHref ( ) || '/' ;
486+ pathPrefix = pathPrefixFromBase ( basePath ) ;
485487 if ( $sniffer . history ) {
486488 $location = new LocationUrl (
487489 convertToHtml5Url ( initUrl , basePath , hashPrefix ) ,
@@ -491,14 +493,14 @@ function $LocationProvider(){
491493 convertToHashbangUrl ( initUrl , basePath , hashPrefix ) ,
492494 hashPrefix ) ;
493495 }
496+ // link rewriting
497+ absUrlPrefix = composeProtocolHostPort (
498+ $location . protocol ( ) , $location . host ( ) , $location . port ( ) ) + pathPrefix ;
494499 } else {
495500 $location = new LocationHashbangUrl ( initUrl , hashPrefix ) ;
501+ absUrlPrefix = $location . absUrl ( ) . split ( '#' ) [ 0 ] ;
496502 }
497503
498- // link rewriting
499- absUrlPrefix = composeProtocolHostPort (
500- $location . protocol ( ) , $location . host ( ) , $location . port ( ) ) + pathPrefix ;
501-
502504 $rootElement . bind ( 'click' , function ( event ) {
503505 // TODO(vojta): rewrite link when opening in new tab/window (in legacy browser)
504506 // currently we open nice url link and redirect then
@@ -512,7 +514,8 @@ function $LocationProvider(){
512514 elm = elm . parent ( ) ;
513515 }
514516
515- var absHref = elm . prop ( 'href' ) ;
517+ var absHref = elm . prop ( 'href' ) ,
518+ href ;
516519
517520 if ( ! absHref ||
518521 elm . attr ( 'target' ) ||
@@ -521,7 +524,9 @@ function $LocationProvider(){
521524 }
522525
523526 // update location with href without the prefix
524- $location . url ( absHref . substr ( absUrlPrefix . length ) ) ;
527+ href = absHref . substr ( absUrlPrefix . length ) ;
528+ if ( href . charAt ( 0 ) == '#' ) href = href . substr ( 1 ) ;
529+ $location . url ( href ) ;
525530 $rootScope . $apply ( ) ;
526531 event . preventDefault ( ) ;
527532 // hack to work around FF6 bug 684208 when scenario runner clicks on links
0 commit comments