扫码关注官方订阅号
在react-router项目里,我想全局监听URL变化来做一些逻辑判断。本来我是通过监听hash来的,但是发现监听hash会触发两次回调。
请问有什么好的解决办法?
业精于勤,荒于嬉;行成于思,毁于随。
可以在根路由组件中监听location.pathname的属性
// route <Route path='/' component={ App }> </Route> // App.jsx componentWillReceiveProps(nextProps){ console.log(nextProps.location.pathname) // path/to/abc }
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
可以在根路由组件中监听location.pathname的属性