Reputation: 111
Since in react-router-dom useHistory
is no longer supported, I am looking for an equivalent to use history.location.pathname
Upvotes: 9
Views: 5687
Reputation: 12964
You have to use useLocation
¹, ² which returns a location object that contains the pathname
and other information about the URL:
const location = useLocation();
console.log(location)
// {
// pathname: "/invoices",
// search: "?filter=sa",
// hash: "",
// state: null,
// key: "ae4cz2j"
// }
Upvotes: 15