You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following will return an empty string which i think is unexpected qs.stringify({}, { addQueryPrefix: true })
i would expect the previous to return "?"
The use case is for many navigating methods including the native replaceState in window.history they discard an empty string while "?" means to empty the url query params.
Yes, imo it would be incorrect to produce a ? when there's nothing in the string; see #213. You can do qs.stringify({}, { addQueryPrefix: true }) || '?' pretty easily if that's something you want.
@ljharb Thanks for the reply. Yea what you suggested is what i already did in my code. But i still think it is worth adding in documentation that addQueryPrefix does not work when stringify produces empty string.
Still i think the way the option is called does not give any indicator that query prefix won't be added when the result is an empty string , and one can do something like the following if not interested in getting just a question mark without anything.
// lodash isEmpty and assuming that params has no undefined values
isEmpty(params) ? "" : qs.stringify(params, { addQueryPrefix: true })
Hey, thank you for the amazing library.
The following will return an empty string which i think is unexpected
qs.stringify({}, { addQueryPrefix: true })
i would expect the previous to return "?"
The use case is for many navigating methods including the native replaceState in window.history they discard an empty string while "?" means to empty the url query params.
I have noticed that this change was introduced in this commit 229b0e9#diff-0b54a0fe4e28dd7c969fecd6711539ca19dcd5cc1e19a175193d805468d863caL208, previously it would work as expected.
The text was updated successfully, but these errors were encountered: