@@ -476,12 +476,14 @@ function $LocationProvider(){
476
476
this . $get = [ '$rootScope' , '$browser' , '$sniffer' , '$rootElement' ,
477
477
function ( $rootScope , $browser , $sniffer , $rootElement ) {
478
478
var $location ,
479
- basePath = $browser . baseHref ( ) || '/' ,
480
- pathPrefix = pathPrefixFromBase ( basePath ) ,
479
+ basePath ,
480
+ pathPrefix ,
481
481
initUrl = $browser . url ( ) ,
482
482
absUrlPrefix ;
483
483
484
484
if ( html5Mode ) {
485
+ basePath = $browser . baseHref ( ) || '/' ;
486
+ pathPrefix = pathPrefixFromBase ( basePath ) ;
485
487
if ( $sniffer . history ) {
486
488
$location = new LocationUrl (
487
489
convertToHtml5Url ( initUrl , basePath , hashPrefix ) ,
@@ -491,14 +493,14 @@ function $LocationProvider(){
491
493
convertToHashbangUrl ( initUrl , basePath , hashPrefix ) ,
492
494
hashPrefix ) ;
493
495
}
496
+ // link rewriting
497
+ absUrlPrefix = composeProtocolHostPort (
498
+ $location . protocol ( ) , $location . host ( ) , $location . port ( ) ) + pathPrefix ;
494
499
} else {
495
500
$location = new LocationHashbangUrl ( initUrl , hashPrefix ) ;
501
+ absUrlPrefix = $location . absUrl ( ) . split ( '#' ) [ 0 ] ;
496
502
}
497
503
498
- // link rewriting
499
- absUrlPrefix = composeProtocolHostPort (
500
- $location . protocol ( ) , $location . host ( ) , $location . port ( ) ) + pathPrefix ;
501
-
502
504
$rootElement . bind ( 'click' , function ( event ) {
503
505
// TODO(vojta): rewrite link when opening in new tab/window (in legacy browser)
504
506
// currently we open nice url link and redirect then
@@ -512,7 +514,8 @@ function $LocationProvider(){
512
514
elm = elm . parent ( ) ;
513
515
}
514
516
515
- var absHref = elm . prop ( 'href' ) ;
517
+ var absHref = elm . prop ( 'href' ) ,
518
+ href ;
516
519
517
520
if ( ! absHref ||
518
521
elm . attr ( 'target' ) ||
@@ -521,7 +524,9 @@ function $LocationProvider(){
521
524
}
522
525
523
526
// 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 ) ;
525
530
$rootScope . $apply ( ) ;
526
531
event . preventDefault ( ) ;
527
532
// hack to work around FF6 bug 684208 when scenario runner clicks on links
0 commit comments