@@ -76,6 +76,41 @@ describe('Integration', () => {
76
76
] ) ;
77
77
} ) ) ) ;
78
78
79
+ describe ( 'relativeLinkResolution' , ( ) => {
80
+ beforeEach ( inject ( [ Router ] , ( router : Router ) => {
81
+ router . resetConfig ( [ {
82
+ path : 'foo' ,
83
+ children : [ { path : 'bar' , children : [ { path : '' , component : RelativeLinkCmp } ] } ]
84
+ } ] ) ;
85
+ } ) ) ;
86
+
87
+ it ( 'should not ignore empty paths in legacy mode' ,
88
+ fakeAsync ( inject ( [ Router ] , ( router : Router ) => {
89
+ router . relativeLinkResolution = 'legacy' ;
90
+
91
+ const fixture = createRoot ( router , RootCmp ) ;
92
+
93
+ router . navigateByUrl ( '/foo/bar' ) ;
94
+ advance ( fixture ) ;
95
+
96
+ const link = fixture . nativeElement . querySelector ( 'a' ) ;
97
+ expect ( link . getAttribute ( 'href' ) ) . toEqual ( '/foo/bar/simple' ) ;
98
+ } ) ) ) ;
99
+
100
+ it ( 'should ignore empty paths in corrected mode' ,
101
+ fakeAsync ( inject ( [ Router ] , ( router : Router ) => {
102
+ router . relativeLinkResolution = 'corrected' ;
103
+
104
+ const fixture = createRoot ( router , RootCmp ) ;
105
+
106
+ router . navigateByUrl ( '/foo/bar' ) ;
107
+ advance ( fixture ) ;
108
+
109
+ const link = fixture . nativeElement . querySelector ( 'a' ) ;
110
+ expect ( link . getAttribute ( 'href' ) ) . toEqual ( '/foo/simple' ) ;
111
+ } ) ) ) ;
112
+ } ) ;
113
+
79
114
it ( 'should set the restoredState to null when executing imperative navigations' ,
80
115
fakeAsync ( inject ( [ Router ] , ( router : Router ) => {
81
116
router . resetConfig ( [
@@ -4030,6 +4065,57 @@ describe('Integration', () => {
4030
4065
] ) ;
4031
4066
} ) ) ) ;
4032
4067
} ) ;
4068
+
4069
+ describe ( 'relativeLinkResolution' , ( ) => {
4070
+ @Component ( { selector : 'link-cmp' , template : `<a [routerLink]="['../simple']">link</a>` } )
4071
+ class RelativeLinkCmp {
4072
+ }
4073
+
4074
+ @NgModule ( {
4075
+ declarations : [ RelativeLinkCmp ] ,
4076
+ imports : [ RouterModule . forChild ( [
4077
+ { path : 'foo/bar' , children : [ { path : '' , component : RelativeLinkCmp } ] } ,
4078
+ ] ) ]
4079
+ } )
4080
+ class LazyLoadedModule {
4081
+ }
4082
+
4083
+ it ( 'should not ignore empty path when in legacy mode' ,
4084
+ fakeAsync ( inject (
4085
+ [ Router , NgModuleFactoryLoader ] ,
4086
+ ( router : Router , loader : SpyNgModuleFactoryLoader ) => {
4087
+ router . relativeLinkResolution = 'legacy' ;
4088
+ loader . stubbedModules = { expected : LazyLoadedModule } ;
4089
+
4090
+ const fixture = createRoot ( router , RootCmp ) ;
4091
+
4092
+ router . resetConfig ( [ { path : 'lazy' , loadChildren : 'expected' } ] ) ;
4093
+
4094
+ router . navigateByUrl ( '/lazy/foo/bar' ) ;
4095
+ advance ( fixture ) ;
4096
+
4097
+ const link = fixture . nativeElement . querySelector ( 'a' ) ;
4098
+ expect ( link . getAttribute ( 'href' ) ) . toEqual ( '/lazy/foo/bar/simple' ) ;
4099
+ } ) ) ) ;
4100
+
4101
+ it ( 'should ignore empty path when in corrected mode' ,
4102
+ fakeAsync ( inject (
4103
+ [ Router , NgModuleFactoryLoader ] ,
4104
+ ( router : Router , loader : SpyNgModuleFactoryLoader ) => {
4105
+ router . relativeLinkResolution = 'corrected' ;
4106
+ loader . stubbedModules = { expected : LazyLoadedModule } ;
4107
+
4108
+ const fixture = createRoot ( router , RootCmp ) ;
4109
+
4110
+ router . resetConfig ( [ { path : 'lazy' , loadChildren : 'expected' } ] ) ;
4111
+
4112
+ router . navigateByUrl ( '/lazy/foo/bar' ) ;
4113
+ advance ( fixture ) ;
4114
+
4115
+ const link = fixture . nativeElement . querySelector ( 'a' ) ;
4116
+ expect ( link . getAttribute ( 'href' ) ) . toEqual ( '/lazy/foo/simple' ) ;
4117
+ } ) ) ) ;
4118
+ } ) ;
4033
4119
} ) ;
4034
4120
4035
4121
describe ( 'Custom Route Reuse Strategy' , ( ) => {
0 commit comments