@@ -541,6 +541,34 @@ describe("Lazy Route Discovery (Fog of War)", () => {
541
541
expect ( router . state . matches . map ( ( m ) => m . route . id ) ) . toEqual ( [ "a" , "b" ] ) ;
542
542
} ) ;
543
543
544
+ it ( "de-prioritizes splat routes in favor of looking for better async matches (splat/*)" , async ( ) => {
545
+ router = createRouter ( {
546
+ history : createMemoryHistory ( ) ,
547
+ routes : [
548
+ {
549
+ path : "/" ,
550
+ } ,
551
+ {
552
+ id : "splat" ,
553
+ path : "/splat/*" ,
554
+ } ,
555
+ ] ,
556
+ async unstable_patchRoutesOnMiss ( { matches, patch } ) {
557
+ await tick ( ) ;
558
+ patch ( null , [
559
+ {
560
+ id : "static" ,
561
+ path : "/splat/static" ,
562
+ } ,
563
+ ] ) ;
564
+ } ,
565
+ } ) ;
566
+
567
+ await router . navigate ( "/splat/static" ) ;
568
+ expect ( router . state . location . pathname ) . toBe ( "/splat/static" ) ;
569
+ expect ( router . state . matches . map ( ( m ) => m . route . id ) ) . toEqual ( [ "static" ] ) ;
570
+ } ) ;
571
+
544
572
it ( "matches splats when other paths don't pan out" , async ( ) => {
545
573
router = createRouter ( {
546
574
history : createMemoryHistory ( ) ,
@@ -628,6 +656,39 @@ describe("Lazy Route Discovery (Fog of War)", () => {
628
656
] ) ;
629
657
} ) ;
630
658
659
+ it ( "discovers routes during initial hydration when a splat route matches" , async ( ) => {
660
+ let childrenDfd = createDeferred < AgnosticDataRouteObject [ ] > ( ) ;
661
+
662
+ router = createRouter ( {
663
+ history : createMemoryHistory ( { initialEntries : [ "/test" ] } ) ,
664
+ routes : [
665
+ {
666
+ path : "/" ,
667
+ } ,
668
+ {
669
+ path : "*" ,
670
+ } ,
671
+ ] ,
672
+ async unstable_patchRoutesOnMiss ( { path, patch, matches } ) {
673
+ let children = await childrenDfd . promise ;
674
+ patch ( null , children ) ;
675
+ } ,
676
+ } ) ;
677
+ router . initialize ( ) ;
678
+ expect ( router . state . initialized ) . toBe ( false ) ;
679
+
680
+ childrenDfd . resolve ( [
681
+ {
682
+ id : "test" ,
683
+ path : "/test" ,
684
+ } ,
685
+ ] ) ;
686
+ await tick ( ) ;
687
+ expect ( router . state . initialized ) . toBe ( true ) ;
688
+ expect ( router . state . location . pathname ) . toBe ( "/test" ) ;
689
+ expect ( router . state . matches . map ( ( m ) => m . route . id ) ) . toEqual ( [ "test" ] ) ;
690
+ } ) ;
691
+
631
692
it ( "discovers new root routes" , async ( ) => {
632
693
let childrenDfd = createDeferred < AgnosticDataRouteObject [ ] > ( ) ;
633
694
let childLoaderDfd = createDeferred ( ) ;
@@ -737,7 +798,7 @@ describe("Lazy Route Discovery (Fog of War)", () => {
737
798
let childLoaderDfd = createDeferred ( ) ;
738
799
739
800
router = createRouter ( {
740
- history : createMemoryHistory ( ) ,
801
+ history : createMemoryHistory ( { initialEntries : [ "/other" ] } ) ,
741
802
routes : [
742
803
{
743
804
id : "other" ,
0 commit comments