react-navigation-current-route
Get the current route name for an application which is using react-navigation
Installation:
npm install react-navigation-current-route --save
Usage:
Pass the
- Get the navigation state, as in redux store ->
navigationState
- Pass
navigationState
to the method exported from react-navigation-current-route - The method returns the current route name 😎
/* Get current route in a container */ ;;;...// Pass the current navigation state objectconst currentRoute = ...// Get the current navigation state from the redux storeconst mapStateToProps = navigationState: ; mapStateToProps null/* component-name*/;
/* Get current route in a middleware like saga */ ;;; // Get the current navigation state from the redux storeconst getNavigationState = ; { const navigationState = ; // Pass the current navigation state object const currentRoute = ; // currentRoute would then have the current route name }
References: