File tree Expand file tree Collapse file tree 2 files changed +36
-3
lines changed
react-router-dom/__tests__ Expand file tree Collapse file tree 2 files changed +36
-3
lines changed Original file line number Diff line number Diff line change @@ -2695,6 +2695,39 @@ function testDomRouter(
2695
2695
"/foo/bar?index&a=1#hash"
2696
2696
) ;
2697
2697
} ) ;
2698
+
2699
+ // eslint-disable-next-line jest/expect-expect
2700
+ it ( 'does not put ?index param in final URL for <Form method="get"' , async ( ) => {
2701
+ let testWindow = getWindow ( "/form" ) ;
2702
+ let router = createTestRouter (
2703
+ createRoutesFromElements (
2704
+ < Route path = "/" >
2705
+ < Route path = "form" >
2706
+ < Route
2707
+ index = { true }
2708
+ element = {
2709
+ < Form >
2710
+ < button type = "submit" name = "name" value = "value" >
2711
+ Submit
2712
+ </ button >
2713
+ </ Form >
2714
+ }
2715
+ />
2716
+ </ Route >
2717
+ </ Route >
2718
+ ) ,
2719
+ {
2720
+ window : testWindow ,
2721
+ }
2722
+ ) ;
2723
+ render ( < RouterProvider router = { router } /> ) ;
2724
+
2725
+ assertLocation ( testWindow , "/form" , "" ) ;
2726
+
2727
+ fireEvent . click ( screen . getByText ( "Submit" ) ) ;
2728
+ await new Promise ( ( r ) => setTimeout ( r , 0 ) ) ;
2729
+ assertLocation ( testWindow , "/form" , "?name=value" ) ;
2730
+ } ) ;
2698
2731
} ) ;
2699
2732
2700
2733
describe ( "dynamic routes" , ( ) => {
Original file line number Diff line number Diff line change @@ -3167,9 +3167,9 @@ function normalizeNavigateOptions(
3167
3167
// Flatten submission onto URLSearchParams for GET submissions
3168
3168
let parsedPath = parsePath ( path ) ;
3169
3169
let searchParams = convertFormDataToSearchParams ( opts . formData ) ;
3170
- // Since fetcher GET submissions only run a single loader (as opposed to
3171
- // navigation GET submissions which run all loaders), we need to preserve
3172
- // any incoming ?index params
3170
+ // On GET navigation submissions we can drop the ?index param from the
3171
+ // resulting location since all loaders will run. But fetcher GET submissions
3172
+ // only run a single loader so we need to preserve any incoming ?index params
3173
3173
if ( isFetcher && parsedPath . search && hasNakedIndexQuery ( parsedPath . search ) ) {
3174
3174
searchParams . append ( "index" , "" ) ;
3175
3175
}
You can’t perform that action at this time.
0 commit comments