get values form query params in next js
To get values from query parameters in Next.js, you can use the useRouter
hook provided by the next/router
package. Here are the steps to do so:
- Import the necessary dependencies:
import { useRouter } from 'next/router';
- Use the
useRouter
hook to access the router object:
const router = useRouter();
- Access the query parameters from the
router.query
object:
const { param1, param2 } = router.query;
In the code above, param1
and param2
are the names of the query parameters you want to retrieve. You can replace them with the actual names of your query parameters.
By following these steps, you will be able to get the values from query parameters in Next.js.