0

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?

1
  • 1
    You should create a next api then call that route... then just create a rewrite or redirect to your homepage or whatever you want to redirect. Commented Feb 14, 2022 at 17:14

4 Answers 4

1

You would want to import useRouter :

import { useRouter } from "next/router";

and inside of your component write this:

const { query } = useRouter();
Sign up to request clarification or add additional context in comments.

Comments

0

import { useRouter } from "next/router";

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

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

return( enter code here ); }

Comments

0

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;

Comments

0

For someone trying to use Routers using dynamic routing in NextJs

import { useRouter } from 'next/router';

const {query} =useRouter();

const id=query.[your file name];

For example:

If your structure has a route Profile and under that you have [username.js].So your code will be like this:

const id=query.username;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.