Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Performing a condition based on the current URL with react.js and react router v6

Using React.js & react router v6

Is there a way I can extract information from the current URL? Let’s say my current URL is this: localhost:3000/about/x567gfh67ssd90g

I simply want to perform a condition based on the current URL. Is there any possible way of doing this?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

const Component = () => {
  const location = useLocation();
  useEffect(() => {
    console.log(location);
  });
  return ();
};

You can get pathname using useLocation.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading