I'm filtering results from an API utilizing query parameters in my Next.js app. I want to use useRouter()
to push multiple different filters with the same key, so my query params could look like:
?page=1&skill=html&skill=css&skill=js
And I can pass each of those parameters to my API request. Right now, when I'm trying to add a skill parameter I'm using router.push
to do it, like this:
const router = useRouter();
const addFilter = (skill: string) => router.push({ query: { ...router.query, skill: skill.toLowerCase() } });
But obviously it's overwriting the previous skill, so I'm only ever getting one of them in the URL. How can I go about adding additional query parameters with the same key, preferably using useRouter()
or next/router
?