react-native-router-flux, how to detect router change?

Viewed 254

I am trying to make analytics logging for screen view whenever the router changed. I am using react-native-router-flux but it seems there is no way to detect that in the guide? Can anyone help me with this? Thanks in advance!

Like below

if (routerChanged) {
  analytics().logScreenView({
    screen_name: currentRouteName,
    screen_class: currentRouteName,
  });
}
1 Answers

Found this. react-native-router-flux API

Worked for me with onStateChange prop function in Router component.

import { Actions, Router, Scene, Stack } from "react-native-router-flux";

<Router
  onStateChange={(e) => {
    console.log("Current screen___", e.routes[e.routes.length - 1].routeName);
    console.log("Current screen___", Actions.currentScene);
  }}
>
  ...
</Router>
Related