It is important because, it gather all information when we move one route to another.
import React from "react";
import { useLocation } from "react-router-dom";
function MyComponent() {
// Access the current location using the useLocation hook
const location = useLocation();
return (
<div>
<h2>Current Pathname:</h2>
<p>{location.pathname}</p>
<h2>Current Search:</h2>
<p>{location.search}</p>
<h2>Current Hash:</h2>
<p>{location.hash}</p>
<h2>Previous State:</h2>
<p>{location.state}</p>
</div>
);
}
export default MyComponent;
© www.thecoderjob.com. All Rights Reserved. Designed by HTML Codex