【发布时间】:2017-01-13 14:54:58
【问题描述】:
我正在使用react-native-router-flux,这是我的路由代码:
<Router navigationBarStyle={navBar} sceneStyle={{ paddingTop: 53}}>
<Scene key="main">
<Scene
key="firstPage"
component={FirstPage}
initial
/>
<Scene
key="secondPage"
component={SecondPage}
/>
</Scene>
</Router>
这是FirstPage 组件的一部分:
class FirstPage extends Component {
constructor(props) {
console.log("constructor");
super(props);
}
componentWillMount(){
console.log("COMPONENT WILL MOUNT");
}
componentDidMount(){
console.log("COMPONENT DID MOUNT");
}
componentWillReceiveProps(){
console.log("COMPONENT WILL RECEIVE PROPS");
}
shouldComponentUpdate(){
console.log("SHOULD COMPONENT UPDATE")
}
componentDidUpdate(){
console.log("COMPONENT DID UPDATE");
}
componentWillUnmount(){
console.log("COMPONENT WILL UNMOUNT");
}
}
打开我的应用程序后,FirstPage 组件已加载,我通过console.logs 得到了这个:
COMPONENT WILL MOUNT
COMPONENT DID MOUNT
SHOULD COMPONENT UPDATE
当我单击将我发送到secondPage 键的按钮时,加载 SecondPage,组件 console.logs 给我这个:
COMPONENT WILL RECEIVE PROPS
SHOULD COMPONENT UPDATE
到这里为止,一切都好。我想要的是能够在我从SecondPage 返回到FirstPage 时触发一个函数。
当我回到FirstPage 时,构造函数、componentWillMount、componentDidMount 等……都没有被触发。
我该怎么做?
【问题讨论】:
标签: reactjs react-native react-native-router-flux