Next Js 13 app-routing router replace
Unanswered
American Shorthair posted this in #help-forum
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
I tried router replace to add new query params
4 Replies
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
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 😦
Siamese
I would use https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams to manage building the string