Next.js Discord

Discord Forum

Next Js 13 app-routing router replace

Unanswered
American Shorthair posted this in #help-forum
Open in Discord
Avatar
American ShorthairOP
Hi guys, how I can dynamicly add and remove query parameter with Next Js useRouter from "next/navigation" with App Routing? I need add filter to query, such as filters=219,213 with .../hotels?id=123&type=hotel, and if I clear state remove this

I tried router replace to add new query params

4 Replies

Avatar
Siamese
from my guess of reading this documentation: https://nextjs.org/docs/app/api-reference/functions/use-router, i'd guess you'd just use router.replace('/hotels?filters=219,213')
i'd include all query params you'd want the new state to be
Avatar
American ShorthairOP
@Siamese yes, its working but it is a bad sollution for me, I have about 8 dynamic query params and I need check if I have another filters like stars count filters 😦
Avatar
Siamese