@@ -2519,6 +2519,35 @@ describe("a router", () => {
2519
2519
expect ( t . router . state . location . pathname ) . toEqual ( "/foo" ) ;
2520
2520
} ) ;
2521
2521
2522
+ it ( "navigates correctly using POP navigations across actions to new locations" , async ( ) => {
2523
+ let t = initializeTmTest ( ) ;
2524
+
2525
+ // Navigate to /foo
2526
+ let A = await t . navigate ( "/foo" ) ;
2527
+ await A . loaders . foo . resolve ( "FOO" ) ;
2528
+ expect ( t . router . state . location . pathname ) . toEqual ( "/foo" ) ;
2529
+
2530
+ // Navigate to /bar
2531
+ let B = await t . navigate ( "/bar" ) ;
2532
+ await B . loaders . bar . resolve ( "BAR" ) ;
2533
+ expect ( t . router . state . location . pathname ) . toEqual ( "/bar" ) ;
2534
+
2535
+ // Post to /baz (should not replace)
2536
+ let C = await t . navigate ( "/baz" , {
2537
+ formMethod : "post" ,
2538
+ formData : createFormData ( { key : "value" } ) ,
2539
+ } ) ;
2540
+ await C . actions . baz . resolve ( "BAZ ACTION" ) ;
2541
+ await C . loaders . root . resolve ( "ROOT" ) ;
2542
+ await C . loaders . baz . resolve ( "BAZ" ) ;
2543
+ expect ( t . router . state . location . pathname ) . toEqual ( "/baz" ) ;
2544
+
2545
+ // POP to /bar
2546
+ let D = await t . navigate ( - 1 ) ;
2547
+ await D . loaders . bar . resolve ( "BAR" ) ;
2548
+ expect ( t . router . state . location . pathname ) . toEqual ( "/bar" ) ;
2549
+ } ) ;
2550
+
2522
2551
it ( "navigates correctly using POP navigations across action errors" , async ( ) => {
2523
2552
let t = initializeTmTest ( ) ;
2524
2553
@@ -2635,6 +2664,42 @@ describe("a router", () => {
2635
2664
expect ( t . router . state . location . key ) . not . toBe ( postBarKey ) ;
2636
2665
} ) ;
2637
2666
2667
+ it ( "navigates correctly using POP navigations across action redirects to the same location" , async ( ) => {
2668
+ let t = initializeTmTest ( ) ;
2669
+
2670
+ // Navigate to /foo
2671
+ let A = await t . navigate ( "/foo" ) ;
2672
+ let fooKey = t . router . state . navigation . location ?. key ;
2673
+ await A . loaders . foo . resolve ( "FOO" ) ;
2674
+ expect ( t . router . state . location . pathname ) . toEqual ( "/foo" ) ;
2675
+
2676
+ // Navigate to /bar
2677
+ let B = await t . navigate ( "/bar" ) ;
2678
+ await B . loaders . bar . resolve ( "BAR" ) ;
2679
+ expect ( t . router . state . historyAction ) . toEqual ( "PUSH" ) ;
2680
+ expect ( t . router . state . location . pathname ) . toEqual ( "/bar" ) ;
2681
+
2682
+ // Post to /bar, redirect to /bar
2683
+ let C = await t . navigate ( "/bar" , {
2684
+ formMethod : "post" ,
2685
+ formData : createFormData ( { key : "value" } ) ,
2686
+ } ) ;
2687
+ let postBarKey = t . router . state . navigation . location ?. key ;
2688
+ let D = await C . actions . bar . redirect ( "/bar" ) ;
2689
+ await D . loaders . root . resolve ( "ROOT" ) ;
2690
+ await D . loaders . bar . resolve ( "BAR" ) ;
2691
+ expect ( t . router . state . historyAction ) . toEqual ( "REPLACE" ) ;
2692
+ expect ( t . router . state . location . pathname ) . toEqual ( "/bar" ) ;
2693
+
2694
+ // POP to /foo
2695
+ let E = await t . navigate ( - 1 ) ;
2696
+ await E . loaders . foo . resolve ( "FOO" ) ;
2697
+ expect ( t . router . state . historyAction ) . toEqual ( "POP" ) ;
2698
+ expect ( t . router . state . location . pathname ) . toEqual ( "/foo" ) ;
2699
+ expect ( t . router . state . location . key ) . toBe ( fooKey ) ;
2700
+ expect ( t . router . state . location . key ) . not . toBe ( postBarKey ) ;
2701
+ } ) ;
2702
+
2638
2703
it ( "navigates correctly using POP navigations across <Form replace> redirects" , async ( ) => {
2639
2704
let t = initializeTmTest ( ) ;
2640
2705
@@ -2667,6 +2732,67 @@ describe("a router", () => {
2667
2732
expect ( t . router . state . historyAction ) . toEqual ( "POP" ) ;
2668
2733
expect ( t . router . state . location . pathname ) . toEqual ( "/foo" ) ;
2669
2734
} ) ;
2735
+
2736
+ it ( "should respect explicit replace:false on non-redirected actions to new locations" , async ( ) => {
2737
+ // start at / (history stack: [/])
2738
+ let t = initializeTmTest ( ) ;
2739
+
2740
+ // Link to /foo (history stack: [/, /foo])
2741
+ let A = await t . navigate ( "/foo" ) ;
2742
+ await A . loaders . root . resolve ( "ROOT" ) ;
2743
+ await A . loaders . foo . resolve ( "FOO" ) ;
2744
+ expect ( t . router . state . historyAction ) . toEqual ( "PUSH" ) ;
2745
+ expect ( t . router . state . location . pathname ) . toEqual ( "/foo" ) ;
2746
+
2747
+ // POST /bar (history stack: [/, /foo, /bar])
2748
+ let B = await t . navigate ( "/bar" , {
2749
+ formMethod : "post" ,
2750
+ formData : createFormData ( { gosh : "dang" } ) ,
2751
+ replace : false ,
2752
+ } ) ;
2753
+ await B . actions . bar . resolve ( "BAR" ) ;
2754
+ await B . loaders . root . resolve ( "ROOT" ) ;
2755
+ await B . loaders . bar . resolve ( "BAR" ) ;
2756
+ expect ( t . router . state . historyAction ) . toEqual ( "PUSH" ) ;
2757
+ expect ( t . router . state . location . pathname ) . toEqual ( "/bar" ) ;
2758
+
2759
+ // POP /foo (history stack: [GET /, GET /foo])
2760
+ let C = await t . navigate ( - 1 ) ;
2761
+ await C . loaders . foo . resolve ( "FOO" ) ;
2762
+ expect ( t . router . state . historyAction ) . toEqual ( "POP" ) ;
2763
+ expect ( t . router . state . location . pathname ) . toEqual ( "/foo" ) ;
2764
+ } ) ;
2765
+
2766
+ it ( "should respect explicit replace:false on non-redirected actions to the same location" , async ( ) => {
2767
+ // start at / (history stack: [/])
2768
+ let t = initializeTmTest ( ) ;
2769
+
2770
+ // Link to /foo (history stack: [/, /foo])
2771
+ let A = await t . navigate ( "/foo" ) ;
2772
+ await A . loaders . root . resolve ( "ROOT" ) ;
2773
+ await A . loaders . foo . resolve ( "FOO" ) ;
2774
+ expect ( t . router . state . historyAction ) . toEqual ( "PUSH" ) ;
2775
+ expect ( t . router . state . location . pathname ) . toEqual ( "/foo" ) ;
2776
+
2777
+ // POST /foo (history stack: [/, /foo, /foo])
2778
+ let B = await t . navigate ( "/foo" , {
2779
+ formMethod : "post" ,
2780
+ formData : createFormData ( { gosh : "dang" } ) ,
2781
+ replace : false ,
2782
+ } ) ;
2783
+ await B . actions . foo . resolve ( "FOO2 ACTION" ) ;
2784
+ await B . loaders . root . resolve ( "ROOT2" ) ;
2785
+ await B . loaders . foo . resolve ( "FOO2" ) ;
2786
+ expect ( t . router . state . historyAction ) . toEqual ( "PUSH" ) ;
2787
+ expect ( t . router . state . location . pathname ) . toEqual ( "/foo" ) ;
2788
+
2789
+ // POP /foo (history stack: [/, /foo])
2790
+ let C = await t . navigate ( - 1 ) ;
2791
+ await C . loaders . root . resolve ( "ROOT3" ) ;
2792
+ await C . loaders . foo . resolve ( "FOO3" ) ;
2793
+ expect ( t . router . state . historyAction ) . toEqual ( "POP" ) ;
2794
+ expect ( t . router . state . location . pathname ) . toEqual ( "/foo" ) ;
2795
+ } ) ;
2670
2796
} ) ;
2671
2797
2672
2798
describe ( "submission navigations" , ( ) => {
@@ -6384,7 +6510,7 @@ describe("a router", () => {
6384
6510
await N . loaders . root . resolve ( "ROOT_DATA*" ) ;
6385
6511
await N . loaders . tasks . resolve ( "TASKS_DATA" ) ;
6386
6512
expect ( t . router . state ) . toMatchObject ( {
6387
- historyAction : "REPLACE " ,
6513
+ historyAction : "PUSH " ,
6388
6514
location : { pathname : "/tasks" } ,
6389
6515
navigation : IDLE_NAVIGATION ,
6390
6516
revalidation : "idle" ,
@@ -6396,7 +6522,7 @@ describe("a router", () => {
6396
6522
tasks : "TASKS_ACTION" ,
6397
6523
} ,
6398
6524
} ) ;
6399
- expect ( t . history . replace ) . toHaveBeenCalledWith (
6525
+ expect ( t . history . push ) . toHaveBeenCalledWith (
6400
6526
t . router . state . location ,
6401
6527
t . router . state . location . state
6402
6528
) ;
@@ -6596,7 +6722,7 @@ describe("a router", () => {
6596
6722
await R . loaders . root . resolve ( "ROOT_DATA*" ) ;
6597
6723
await R . loaders . tasks . resolve ( "TASKS_DATA*" ) ;
6598
6724
expect ( t . router . state ) . toMatchObject ( {
6599
- historyAction : "REPLACE " ,
6725
+ historyAction : "PUSH " ,
6600
6726
location : { pathname : "/tasks" } ,
6601
6727
navigation : IDLE_NAVIGATION ,
6602
6728
revalidation : "idle" ,
@@ -6605,7 +6731,7 @@ describe("a router", () => {
6605
6731
tasks : "TASKS_DATA*" ,
6606
6732
} ,
6607
6733
} ) ;
6608
- expect ( t . history . replace ) . toHaveBeenCalledWith (
6734
+ expect ( t . history . push ) . toHaveBeenCalledWith (
6609
6735
t . router . state . location ,
6610
6736
t . router . state . location . state
6611
6737
) ;
@@ -6683,7 +6809,7 @@ describe("a router", () => {
6683
6809
await R . loaders . root . resolve ( "ROOT_DATA*" ) ;
6684
6810
await R . loaders . tasks . resolve ( "TASKS_DATA*" ) ;
6685
6811
expect ( t . router . state ) . toMatchObject ( {
6686
- historyAction : "REPLACE " ,
6812
+ historyAction : "PUSH " ,
6687
6813
location : { pathname : "/tasks" } ,
6688
6814
navigation : IDLE_NAVIGATION ,
6689
6815
revalidation : "idle" ,
@@ -6695,7 +6821,7 @@ describe("a router", () => {
6695
6821
tasks : "TASKS_ACTION" ,
6696
6822
} ,
6697
6823
} ) ;
6698
- expect ( t . history . replace ) . toHaveBeenCalledWith (
6824
+ expect ( t . history . push ) . toHaveBeenCalledWith (
6699
6825
t . router . state . location ,
6700
6826
t . router . state . location . state
6701
6827
) ;
0 commit comments