Skip to content

Instantly share code, notes, and snippets.

@chrisza4
Created October 26, 2019 14:42
Show Gist options
  • Select an option

  • Save chrisza4/37a9062bf1e496885a0c7fe52ebe894f to your computer and use it in GitHub Desktop.

Select an option

Save chrisza4/37a9062bf1e496885a0c7fe52ebe894f to your computer and use it in GitHub Desktop.
Hack navigation to alert
function getActiveRouteName(navigationState) {
if (!navigationState) {
return null
}
const route = navigationState.routes[navigationState.index]
// dive into nested navigators
if (route.routes) {
return getActiveRouteName(route)
}
return route.routeName
}
<Navigations
onNavigationStateChange={(prevState, nextState) => {
if (getActiveRouteName(prevState) === 'logout') {
// Do something
alert('Logout')
}
}}
/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment