I’m using Next.js with TypeScript and I want to navigate to a new page and want to include the URL parameters as well. How do i do that?
For example I’m at http://localhost:3000/
and I want to navigate to http://localhost:3000/path?queryParam=value
by clicking on a button.
2
Answers
'use client'
on the top of your component.useRouter
hook fromnext/navigation
.URLSearchParams
.URLSearchParams
.For example:
Sources:
You can achieve this by combining the
usePathname
,useRouter
and theuseSearchParams
hooks.