Next.js Discord

Discord Forum

How to add paramters in URl, using the nextJs app router

Answered
West African Lion posted this in #help-forum
Open in Discord
West African LionOP
I have been trying to add search params for ever now using the nextjs app router and it's giving me errors
  const router = useRouter();
    router.push('/search/?v='+ version)
i had some thing like this and i have been trying but it's not working
Answered by Turkish Van
Make sure the useRouter hook is imported from next/navigation and not next/router when using the App Router.

In order for me to assist further, You will have to provide a bit more details about the problem You are facing.
View full answer

6 Replies

Original message was deleted
West African LionOP
i also tried this
const sp = new URLSearchParams();
all i'm trying to do is add a parameter to my existing URL on some react events, i have not been able to get any results and i can't find anything in the documentaion
@West African Lion I have been trying to add search params for ever now using the nextjs app router and it's giving me errors const router = useRouter(); router.push('/search/?v='+ version) i had some thing like this and i have been trying but it's not working
Turkish Van
Make sure the useRouter hook is imported from next/navigation and not next/router when using the App Router.

In order for me to assist further, You will have to provide a bit more details about the problem You are facing.
Answer
@West African Lion thanks, i was able to figure out something tho
Turkish Van
Make sure to mark it as answered, so thread gets closed!

Glad to help!
@Turkish Van Make sure to mark it as answered, so thread gets closed! Glad to help!
West African LionOP
great, but how
@West African Lion great, but how
Turkish Van
Right click on the answer > Apps > Mark Solution