react-native-router-flux - trigger function on specific route load

Viewed 2790

I am trying to trigger a function whenever a specific route within a router loads. I am using react-native-router-flux 2.x and ReactNative 0.21 (Can't update to 3.x right now).

For example below I just want to trigger a function whenever screen2 is loaded. Is this possible? I tried using onPush but it didn't seem to work.

The reason I need this is because I cannot use componentDidMount, componentWillMount for the screen2 component as it will only load the first time the component is called. I need a function to trigger every time the route is selected. Thanks!

  <Route name="screen1" initial={!needSignIn}>
    <Router footer={TabBar} hideNavBar={true} >
      <Route name="screen1" hideNavBar={true} title="Screen1" schema="tab" component={Screen1} />
      <Route onPush={()=>{console.log("onPush is called!");}} name="screen2" hideNavBar={true} title="Screen2" schema="tab" component={Screen2} />
      <Route name="screen3" hideNavBar={true} title="Screen2" schema="tab" component={Screen3} />
    </Router>
  </Route>
1 Answers
Related