Skip to content

Commit 371dba9

Browse files
committed
fix(core): have router.reload data replace query params
Fixes the bug where outer.reload would merge new data with existing query params instead of replacing them. With this change, the provided data object is now treated as the single source of truth for the new query string, which makes the behavior predictable. Fixes: #2285
1 parent a7a9cac commit 371dba9

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

packages/core/src/url.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { mergeWith } from 'es-toolkit'
21
import * as qs from 'qs'
32
import { hasFiles } from './files'
43
import { isFormData, objectToFormData } from './formData'
@@ -45,17 +44,10 @@ export function mergeDataIntoQueryString(
4544
const url = new URL(href.toString(), 'http://localhost')
4645

4746
if (method === 'get' && Object.keys(data).length) {
48-
url.search = qs.stringify(
49-
mergeWith(qs.parse(url.search, { ignoreQueryPrefix: true }), data, (_, sourceValue, key, target) => {
50-
if (sourceValue === undefined) {
51-
delete target[key]
52-
}
53-
}),
54-
{
55-
encodeValuesOnly: true,
56-
arrayFormat: qsArrayFormat,
57-
},
58-
)
47+
url.search = qs.stringify(data, {
48+
encodeValuesOnly: true,
49+
arrayFormat: qsArrayFormat,
50+
})
5951
data = {}
6052
}
6153

0 commit comments

Comments
 (0)