【发布时间】:2018-04-11 11:45:04
【问题描述】:
我正在使用 react-router v 4.2 并遇到了一些问题。有两个组件:
第一个是:
class One extends React.Component {
componentWillMount() {
console.log('One mount');
}
componentWillUnmount() {
console.log('One unmount');
}
render() {
...
}
}
第二个是:
class Two extends React.Component {
componentWillMount() {
console.log('Two mount');
}
componentWillUnmount() {
console.log('Two unmount');
}
render() {
...
}
}
当我将页面从组件一转到组件二时。回到一。我会得到:
一个坐骑> 一卸 > 二装 > 一个坐骑 > 两个卸载
首先安装一个,然后卸载两个。真奇怪!然后,我尝试将 react-router 更改为 v3.0.0,然后问题就消失了!所以我认为这是 v4.2 中的问题
【问题讨论】:
-
codepen 示例:codepen.io/Chuckthwu/pen/JOoOVp?editors=1111
-
v2.0中的codepen示例(正确示例):codepen.io/Chuckthwu/pen/RjNxwv?editors=1111
标签: react-router-v4