kit
kit copied to clipboard
Cannot fully clear query params with pushState
Describe the problem
I am using query params on a search page to store things like ?tags=foo,bar and when the user inputs an "empty" search (e.g. no tags filter), I want to clear away all the query params on the page. The problem is, pushState treats pushState('', {}) as a special call that does not update the route. The best I can do is pushState('?', {}) which leaves an ugly question mark in my url like so: /browse?.
Describe the proposed solution
What I would like is a way to fully clear away query params and the lingering ? character. I'm thinking this can either be the default behavior of pushState('?', {}) or it could be a special flag added like pushState('', {clearQueryParams: true})
Alternatives considered
No response
Importance
nice to have
Additional Information
No response
The vanilla pushState works by resolving the URL you pass it against the current URL, which is why calling with '' gives you the same URL.
Does calling pushState with location.pathname not work?