In React Router, the location object represents the current URL and provides details like pathname, search, and hash.
Significance:
Tracks the current route.
Allows conditional rendering based on the URL.
Helps manage navigation state (e.g., modals, redirects).
Usage in Components:
Use the useLocation() hook:
import { useLocation } from 'react-router-dom';
function MyComponent() {
const location = useLocation();
console.log(location.pathname); // Current path
console.log(location.search); // Query params
console.log(location.hash); // URL hash
return <div>Current route: {location.pathname}</div>;
}