backtrack论坛,婢女丞相,北原香菜
"componentwillreceiveprops" "shouldcomponentupdate" "componentwillupdate" "render" "componentdidupdate"
使用这些生命周期钩子可以监听到路由相同,参数不同的变化,但是监听不到完全不相同的url的变化。即使路由不同,componentdidmount组件内容所更新的东西变了,但是代码变了,页面没有变,找到了一种方法。withrouter
参考:https://reacttraining.com/react-router/web/api/withrouter
import react from 'react' import proptypes from 'prop-types' import { withrouter } from 'react-router' // a simple component that shows the pathname of the current location class showthelocation extends react.component { static proptypes = { match: proptypes.object.isrequired, location: proptypes.object.isrequired, history: proptypes.object.isrequired } render() { const { match, location, history } = this.props return ( <div>you are now at {location.pathname}</div> ) } } export default withrouter(showthelocation) //组件名称,导出该组件,保证在最外边
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Object.keys() 和 Object.getOwnPropertyNames() 的区别详解
JavaScript使用prototype属性实现继承操作示例
JavaScript直接调用函数与call调用的区别实例分析
JavaScript设计模式--简单工厂模式实例分析【XHR工厂案例】
网友评论