1.简介
该useLocation
挂钩返回代表当前URL的location对象。您可以将其视为类似于URL更改时useState
会返回新值的location
。
2.API
位置表示应用程序现在所在的位置,您希望其运行的位置,甚至是以前的位置。看起来像这样:
{
key: 'ac3df4', // not with HashHistory!
pathname: '/somewhere',
search: '?some=search-string',
hash: '#howdy',
state: {
[userDefined]: true
}
}
路由器将在几个地方为您提供位置对象:
- Route Component中为
this.props.location
- Route render中为
({ location }) => ()
- Route children中为
({ location }) => ()
- withRouter中为
this.props.location
</