How to parse the complete link in the url query string?

URL: https://n9hon.csb.app?name=netflix&url=https://localhost?apikey=123&code=321

code:

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

function useQuery() {
  const {search} = useLocation();
  const query = new URLSearchParams(search);
  console.log('name: ', query.get('name'))
  console.log('url: ', query.get('url'))
  return query
}

Output:

name:  netflix 
url:  https://localhost?apikey=123 

As you can see, the code parameter is lost. I expect the value of url parameter should be https://localhost?apikey=123&code=321.

Source: Ask Javascript Questions

LEAVE A COMMENT