Since in react-router-dom useHistory
is no longer supported, I am looking for an equivalent to use history.location.pathname
CodePudding user response:
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"
// }