Next.js Discord

Discord Forum

How do I remove a specific query from pathname in client component?

Unanswered
Rufous Hummingbird posted this in #help-forum
Open in Discord
Rufous HummingbirdOP
Let's say we have a path such as http://localhost:3000/?object={number}&modal=open&search={string}.

How can I remove the 'object' query so that the url now becomes http://localhost:3000/?modal=open&search={string} ?

And then router.push this new url, this would all be happening in a client component.

2 Replies

This should be all you need. It uses useSearchParams() to provide a read-only version of all the search parameters. Change the parameters as you like and use router.push() or Link with the new query params.

Its a code example so it shouldn't be too hard to understand