我使用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.log
S:
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等等。
我該如何解決這個問題?