0

I have a URL like this that is created by external parties.

https://localhost:3001/succesful?code=3434443A&scope=xyz

I need to find the code and scope from the URL.

I tried to do it like this but not working

    const { code, scope} = useParams();

Could someone help me?

1

2 Answers 2

2

Make sure you are using the react-router-dom library for the below solution.

import {    useSearchParams } from "react-router-dom";

You can refer to the below piece of code to fetch the information from the URL and use it in a particular component.

const [queryParameters] = useSearchParams()

and you can fetch code and scope like:

{queryParameters.get("code")}
{queryParameters.get("scope")}
Sign up to request clarification or add additional context in comments.

Comments

0
import {useSearchParams} from "react-router-dom"

function Home() {
  const [queryParameters] = useSearchParams()

  return (
    <div>
      <p>Type: {queryParameters.get("code")}</p>
      <p>Name: {queryParameters.get("scope")}</p>
    </div>
  )
}

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.