pratibimbam
pratibimbam

Reputation: 111

react-router-dom v6 useHistory location.pathname

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

Answers (1)

Fraction
Fraction

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

Related Questions