omr*_*n12 3 javascript reactjs react-router
我正在使用react-router Link我的 SPA 应用程序导航。
在某些情况下,我会遇到从页面到具有相同参数的完全相同页面的链接,例如:
我在../page1/2,我有一个指向同一条路线的链接:
<Link to='/page1/2'>
click me
</Link>
Run Code Online (Sandbox Code Playgroud)
我的问题是,在这种情况下componentWillUnmount,componentDidMount并没有开火,只有componentDidUpdate.
这是有问题的,因为我需要在componentWillUnmount.
解决办法是什么?
您必须检查 componentWillReceiveProps 以处理此更改,react-router 识别组件处于活动状态并且不要卸载组件,只需传递新属性。
componentWillReceiveProps (nextProps) {
if(nextProps.id === this.props.id) {
// Clean component and reload?
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6097 次 |
| 最近记录: |