Closed mikenikles closed 8 months ago
The problem I see with this is that technically when the search param is not there the value is null
. In some occasions having it disappear would be good in other would be bad.
However there is a better solution: you can use the default of '' and set showDefaults
to false
<script lang="ts">
import { queryParam, ssp } from 'sveltekit-search-params';
const search = queryParam('search', ssp.string(''), {
showDefaults: false,
});
</script>
EDIT: string, not number lol
Oh, very elegant. I missed that in the release notes 😊.
Describe the problem
I have a
search
query string parameter bound to a search input field. Ideally, when the search input field is empty, I'd like to see thesearch
query string disappear from the URL. Currently, it shows?search=
.Describe the proposed solution
The current solution is this:
Then use it as follows: