nandorojo / solito

🧍‍♂️ React Native + Next.js, unified.
https://solito.dev
MIT License
3.35k stars 169 forks source link

Excessive question mark using `useUpdateSearchParams` #455

Closed luixo closed 4 months ago

luixo commented 6 months ago

Is there an existing issue for this?

Do you want this issue prioritized?

Current Behavior

When using useUpdateSearchParams, if no parameters are in the resulting URLSearchParams - the url is updated to http://localhost:3000/page?

Expected Behavior

Trailing question mark should be removed if no parameters are present.

The fix should should be to replace this line:

  const action =
    router[options?.webBehavior ?? (shouldReplace ? 'replace' : 'push')]

-  action(`${pathname}?${next.toString()}`)
+  const stringifiedNext = next.toString();
+  action(`${pathname}${stringifiedNext ? `?${stringifiedNext}` : ''}`)
},

Steps To Reproduce

No response

Versions

- Solito: 4.1.3
- Next.js: 14.0.3
- Expo: -
- React Native: -

Screenshots

No response

Reproduction

No response

nandorojo commented 6 months ago

Happy to merge a PR