@@ -779,15 +779,22 @@ describe('$location', function() {
779
779
780
780
var root , link , originalBrowser , lastEventPreventDefault ;
781
781
782
- function configureService ( linkHref , html5Mode , supportHist , attrs , content ) {
782
+ function configureService ( linkHref , html5Mode , supportHist , relLink , attrs , content ) {
783
+ if ( typeof relLink !== "boolean" ) {
784
+ content = attrs ;
785
+ attrs = relLink ;
786
+ relLink = false ;
787
+ }
783
788
module ( function ( $provide , $locationProvider ) {
784
789
attrs = attrs ? ' ' + attrs + ' ' : '' ;
785
790
786
791
// fake the base behavior
787
- if ( linkHref [ 0 ] == '/' ) {
788
- linkHref = 'http://host.com' + linkHref ;
789
- } else if ( ! linkHref . match ( / : \/ \/ / ) ) {
790
- linkHref = 'http://host.com/base/' + linkHref ;
792
+ if ( ! relLink ) {
793
+ if ( linkHref [ 0 ] == '/' ) {
794
+ linkHref = 'http://host.com' + linkHref ;
795
+ } else if ( ! linkHref . match ( / : \/ \/ / ) ) {
796
+ linkHref = 'http://host.com/base/' + linkHref ;
797
+ }
791
798
}
792
799
793
800
link = jqLite ( '<a href="' + linkHref + '"' + attrs + '>' + content + '</a>' ) [ 0 ] ;
@@ -1067,6 +1074,51 @@ describe('$location', function() {
1067
1074
} ) ;
1068
1075
1069
1076
1077
+ it ( 'should rewrite relative links relative to current path when history disabled' , function ( ) {
1078
+ configureService ( 'link' , true , false , true ) ;
1079
+ inject (
1080
+ initBrowser ( ) ,
1081
+ initLocation ( ) ,
1082
+ function ( $browser , $location ) {
1083
+ $location . path ( '/some' ) ;
1084
+ browserTrigger ( link , 'click' ) ;
1085
+ expectRewriteTo ( $browser , 'http://host.com/base/index.html#!/some/link' ) ;
1086
+ }
1087
+ ) ;
1088
+ } ) ;
1089
+
1090
+
1091
+ it ( 'should replace current path when link begins with "/" and history disabled' , function ( ) {
1092
+ configureService ( '/link' , true , false , true ) ;
1093
+ inject (
1094
+ initBrowser ( ) ,
1095
+ initLocation ( ) ,
1096
+ function ( $browser , $location ) {
1097
+ $location . path ( '/some' ) ;
1098
+ browserTrigger ( link , 'click' ) ;
1099
+ expectRewriteTo ( $browser , 'http://host.com/base/index.html#!/link' ) ;
1100
+ }
1101
+ ) ;
1102
+ } ) ;
1103
+
1104
+
1105
+ it ( 'should replace current hash fragment when link begins with "#" history disabled' , function ( ) {
1106
+ configureService ( '#link' , true , false , true ) ;
1107
+ inject (
1108
+ initBrowser ( ) ,
1109
+ initLocation ( ) ,
1110
+ function ( $browser , $location ) {
1111
+ // Initialize browser URL
1112
+ $location . path ( '/some' ) ;
1113
+ $location . hash ( 'foo' ) ;
1114
+ browserTrigger ( link , 'click' ) ;
1115
+ expect ( $location . hash ( ) ) . toBe ( 'link' ) ;
1116
+ expectRewriteTo ( $browser , 'http://host.com/base/index.html#!/some#link' ) ;
1117
+ }
1118
+ ) ;
1119
+ } ) ;
1120
+
1121
+
1070
1122
// don't run next tests on IE<9, as browserTrigger does not simulate pressed keys
1071
1123
if ( ! ( msie < 9 ) ) {
1072
1124
0 commit comments