Home > Net >  Get URL Params before server Next js render
Get URL Params before server Next js render

Time:02-15

I am trying to get the params in a url redirected from the Spotify api, ex: http//link.com/?code=examplecode How can I get the value of code before it renders so I can redirect it and pass the code value to another page?

CodePudding user response:

You would want to import useRouter :

import { useRouter } from "next/router";

and inside of your component write this:

const { query } = useRouter();

CodePudding user response:

Read the article, it will solve the problem hopefully.. https://reactgo.com/next-get-query-params/

CodePudding user response:

import { useRouter } from "next/router";

const App=()=>{ const query = useRouter();

console.log(query) //to view the params

return( enter code here ); }

CodePudding user response:

I was able to figure it out and I'll leave it here in case someone needs it.

import { useRouter } from "next/router"

const router = useRouter();
const code = router.query.code;
  • Related