[英]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
由于在 react-router-dom 中不再支持
useHistory
,我正在寻找一个等效于 use history.location.pathname
You have to use useLocation
¹ , ² which returns a location object that contains the pathname
and other information about the URL:您必须使用
useLocation
¹ , ²它返回一个位置 object,其中包含有关 URL 的pathname
和其他信息:
const location = useLocation();
console.log(location)
// {
// pathname: "/invoices",
// search: "?filter=sa",
// hash: "",
// state: null,
// key: "ae4cz2j"
// }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.