@@ -115,31 +115,30 @@ describe('createUrlTree', async () => {
115
115
expect ( serializer . serialize ( t ) ) . toEqual ( '/%2Fone/two%2Fthree' ) ;
116
116
} ) ;
117
117
118
- it ( 'should preserve secondary segments' , async ( ) => {
119
- const p = serializer . parse ( '/a/11/b(right:c)' ) ;
120
- const t = await createRoot ( p , [ '/a' , 11 , 'd' ] ) ;
121
- expect ( serializer . serialize ( t ) ) . toEqual ( '/a/11/d(right:c)' ) ;
122
- } ) ;
123
-
124
- it ( 'should support updating secondary segments (absolute)' , async ( ) => {
125
- const p = serializer . parse ( '/a(right:b)' ) ;
126
- const t = await createRoot ( p , [ '/' , { outlets : { right : [ 'c' ] } } ] ) ;
127
- expect ( serializer . serialize ( t ) ) . toEqual ( '/a(right:c)' ) ;
128
- } ) ;
118
+ describe ( 'named outlets' , async ( ) => {
119
+ it ( 'should preserve secondary segments' , async ( ) => {
120
+ const p = serializer . parse ( '/a/11/b(right:c)' ) ;
121
+ const t = await createRoot ( p , [ '/a' , 11 , 'd' ] ) ;
122
+ expect ( serializer . serialize ( t ) ) . toEqual ( '/a/11/d(right:c)' ) ;
123
+ } ) ;
129
124
130
- it ( 'should support updating secondary segments' , async ( ) => {
131
- const p = serializer . parse ( '/a(right:b)' ) ;
132
- const t = await createRoot ( p , [ { outlets : { right : [ 'c' , 11 , 'd '] } } ] ) ;
133
- expect ( serializer . serialize ( t ) ) . toEqual ( '/a(right:c/11/d )' ) ;
134
- } ) ;
125
+ it ( 'should support updating secondary segments (absolute) ' , async ( ) => {
126
+ const p = serializer . parse ( '/a(right:b)' ) ;
127
+ const t = await createRoot ( p , [ '/' , { outlets : { right : [ 'c' ] } } ] ) ;
128
+ expect ( serializer . serialize ( t ) ) . toEqual ( '/a(right:c)' ) ;
129
+ } ) ;
135
130
136
- it ( 'should support updating secondary segments (nested case) ' , async ( ) => {
137
- const p = serializer . parse ( '/a/(b// right:c )' ) ;
138
- const t = await createRoot ( p , [ 'a' , { outlets : { right : [ 'd ' , 11 , 'e ' ] } } ] ) ;
139
- expect ( serializer . serialize ( t ) ) . toEqual ( '/a/(b// right:d /11/e )' ) ;
140
- } ) ;
131
+ it ( 'should support updating secondary segments' , async ( ) => {
132
+ const p = serializer . parse ( '/a( right:b )' ) ;
133
+ const t = await createRoot ( p , [ { outlets : { right : [ 'c ' , 11 , 'd ' ] } } ] ) ;
134
+ expect ( serializer . serialize ( t ) ) . toEqual ( '/a( right:c /11/d )' ) ;
135
+ } ) ;
141
136
142
- describe ( '' , async ( ) => {
137
+ it ( 'should support updating secondary segments (nested case)' , async ( ) => {
138
+ const p = serializer . parse ( '/a/(b//right:c)' ) ;
139
+ const t = await createRoot ( p , [ 'a' , { outlets : { right : [ 'd' , 11 , 'e' ] } } ] ) ;
140
+ expect ( serializer . serialize ( t ) ) . toEqual ( '/a/(b//right:d/11/e)' ) ;
141
+ } ) ;
143
142
it ( 'should support removing secondary outlet with prefix' , async ( ) => {
144
143
const p = serializer . parse ( '/parent/(child//secondary:popup)' ) ;
145
144
const t = await createRoot ( p , [ 'parent' , { outlets : { secondary : null } } ] ) ;
@@ -206,6 +205,106 @@ describe('createUrlTree', async () => {
206
205
const t = await createRoot ( p , [ 'parent' , { outlets : { primary : 'child' , secondary : null } } ] ) ;
207
206
expect ( serializer . serialize ( t ) ) . toEqual ( '/parent/child(rootSecondary:rootPopup)' ) ;
208
207
} ) ;
208
+
209
+ describe ( 'absolute navigations' , ( ) => {
210
+ it ( 'with and pathless root' , async ( ) => {
211
+ router . resetConfig ( [
212
+ {
213
+ path : '' ,
214
+ children : [
215
+ { path : '**' , outlet : 'left' , component : class { } } ,
216
+ ] ,
217
+ } ,
218
+ ] ) ;
219
+ await router . navigateByUrl ( '(left:search)' ) ;
220
+ expect ( router . url ) . toEqual ( '/(left:search)' ) ;
221
+ expect ( router . createUrlTree ( [ '/' , { outlets : { 'left' : [ 'projects' , '123' ] } } ] ) . toString ( ) )
222
+ . toEqual ( '/(left:projects/123)' ) ;
223
+ } ) ;
224
+ it ( 'empty path parent and sibling with a path' , async ( ) => {
225
+ router . resetConfig ( [
226
+ {
227
+ path : '' ,
228
+ children : [
229
+ { path : 'x' , component : class { } } ,
230
+ { path : '**' , outlet : 'left' , component : class { } } ,
231
+ ] ,
232
+ } ,
233
+ ] ) ;
234
+ await router . navigateByUrl ( '/x(left:search)' ) ;
235
+ expect ( router . url ) . toEqual ( '/x(left:search)' ) ;
236
+ expect ( router . createUrlTree ( [ '/' , { outlets : { 'left' : [ 'projects' , '123' ] } } ] ) . toString ( ) )
237
+ . toEqual ( '/x(left:projects/123)' ) ;
238
+ // TODO(atscott): router.createUrlTree uses the "legacy" strategy based on the current
239
+ // UrlTree to generate new URLs. Once that changes, this can be `router.createUrlTree`
240
+ // again.
241
+ expect ( createUrlTreeFromSnapshot (
242
+ router . routerState . root . snapshot ,
243
+ [
244
+ '/' , {
245
+ outlets : {
246
+ 'primary' : [ {
247
+ outlets : {
248
+ 'left' : [ 'projects' , '123' ] ,
249
+ }
250
+ } ]
251
+ }
252
+ }
253
+ ] )
254
+ . toString ( ) )
255
+ . toEqual ( '/x(left:projects/123)' ) ;
256
+ } ) ;
257
+
258
+ it ( 'empty path parent and sibling' , async ( ) => {
259
+ router . resetConfig ( [
260
+ {
261
+ path : '' ,
262
+ children : [
263
+ { path : '' , component : class { } } ,
264
+ { path : '**' , outlet : 'left' , component : class { } } ,
265
+ { path : '**' , outlet : 'right' , component : class { } } ,
266
+ ] ,
267
+ } ,
268
+ ] ) ;
269
+ await router . navigateByUrl ( '/(left:search//right:define)' ) ;
270
+ expect ( router . url ) . toEqual ( '/(left:search//right:define)' ) ;
271
+ expect ( router . createUrlTree ( [ '/' , { outlets : { 'left' : [ 'projects' , '123' ] } } ] ) . toString ( ) )
272
+ . toEqual ( '/(left:projects/123//right:define)' ) ;
273
+ } ) ;
274
+ it ( 'two pathless parents' , async ( ) => {
275
+ router . resetConfig ( [
276
+ {
277
+ path : '' ,
278
+ children : [ {
279
+ path : '' ,
280
+ children : [
281
+ { path : '**' , outlet : 'left' , component : class { } } ,
282
+ ]
283
+ } ] ,
284
+ } ,
285
+ ] ) ;
286
+ await router . navigateByUrl ( '(left:search)' ) ;
287
+ expect ( router . url ) . toEqual ( '/(left:search)' ) ;
288
+ expect ( router . createUrlTree ( [ '/' , { outlets : { 'left' : [ 'projects' , '123' ] } } ] ) . toString ( ) )
289
+ . toEqual ( '/(left:projects/123)' ) ;
290
+ } ) ;
291
+
292
+ it ( 'maintains structure when primary outlet is not pathless' , async ( ) => {
293
+ router . resetConfig ( [
294
+ {
295
+ path : 'a' ,
296
+ children : [
297
+ { path : '**' , outlet : 'left' , component : class { } } ,
298
+ ] ,
299
+ } ,
300
+ { path : '**' , outlet : 'left' , component : class { } } ,
301
+ ] ) ;
302
+ await router . navigateByUrl ( '/a/(left:search)' ) ;
303
+ expect ( router . url ) . toEqual ( '/a/(left:search)' ) ;
304
+ expect ( router . createUrlTree ( [ '/' , { outlets : { 'left' : [ 'projects' , '123' ] } } ] ) . toString ( ) )
305
+ . toEqual ( '/a/(left:search)(left:projects/123)' ) ;
306
+ } ) ;
307
+ } ) ;
209
308
} ) ;
210
309
211
310
it ( 'can navigate to nested route where commands is string' , async ( ) => {
0 commit comments