nandorojo / solito

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

Excessive question mark using `useUpdateSearchParams` #455

Closed luixo closed 9 months ago

luixo commented 11 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 11 months ago

Happy to merge a PR