@@ -488,3 +488,63 @@ describe('router.navigate navigation using layout routes resolves correctly', ()
488
488
expect ( router . state . location . search ) . toStrictEqual ( { 'foo=bar' : 3 } )
489
489
} )
490
490
} )
491
+
492
+ describe ( 'relative navigation' , ( ) => {
493
+ it ( 'should navigate to a child route' , async ( ) => {
494
+ const { router } = createTestRouter (
495
+ createMemoryHistory ( { initialEntries : [ '/posts' ] } ) ,
496
+ )
497
+
498
+ await router . load ( )
499
+
500
+ expect ( router . state . location . pathname ) . toBe ( '/posts' )
501
+
502
+ await router . navigate ( {
503
+ from : '/posts' ,
504
+ to : './$slug' ,
505
+ params : { slug : 'tkdodo' } ,
506
+ } )
507
+
508
+ await router . invalidate ( )
509
+
510
+ expect ( router . state . location . pathname ) . toBe ( '/posts/tkdodo' )
511
+ } )
512
+
513
+ it ( 'should navigate to a parent route' , async ( ) => {
514
+ const { router } = createTestRouter (
515
+ createMemoryHistory ( { initialEntries : [ '/posts/tanner' ] } ) ,
516
+ )
517
+
518
+ await router . load ( )
519
+
520
+ expect ( router . state . location . pathname ) . toBe ( '/posts/tanner' )
521
+
522
+ await router . navigate ( {
523
+ to : '..' ,
524
+ } )
525
+
526
+ await router . invalidate ( )
527
+
528
+ expect ( router . state . location . pathname ) . toBe ( '/posts' )
529
+ } )
530
+
531
+ it ( 'should navigate to a sibling route' , async ( ) => {
532
+ const { router } = createTestRouter (
533
+ createMemoryHistory ( { initialEntries : [ '/posts/tanner' ] } ) ,
534
+ )
535
+
536
+ await router . load ( )
537
+
538
+ expect ( router . state . location . pathname ) . toBe ( '/posts/tanner' )
539
+
540
+ await router . navigate ( {
541
+ from : '/posts/$slug' ,
542
+ to : '.' ,
543
+ params : { slug : 'tkdodo' } ,
544
+ } )
545
+
546
+ await router . invalidate ( )
547
+
548
+ expect ( router . state . location . pathname ) . toBe ( '/posts/tkdodo' )
549
+ } )
550
+ } )
0 commit comments