Skip to content

Commit 21cc53d

Browse files
committed
fix(utils): fix redirect search params
1 parent 2350dd6 commit 21cc53d

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

packages/forms/src/form-tools/forms-react.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,22 @@ export default class FormsReact {
4545

4646
return {
4747
search,
48-
redirect(status?: ValidRedirectStatus) {
49-
const pathWithSearch = url.pathname.split('/').pop() + search.toString();
48+
redirect(status?: ValidRedirectStatus, removeEmptyParams = true) {
49+
const copySearch = new URLSearchParams(search);
50+
if (removeEmptyParams) {
51+
for (const [key, value] of copySearch.entries()) {
52+
if (value === '' || value == null) {
53+
copySearch.delete(key);
54+
}
55+
}
56+
}
57+
58+
const searchString = copySearch.toString();
59+
let pathWithSearch = url.pathname.split('/').pop();
60+
if (searchString) {
61+
pathWithSearch += '?' + searchString;
62+
}
63+
5064
self.overrideResponse = new Response(null, {
5165
status: status || 302,
5266
headers: {

0 commit comments

Comments
 (0)