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 :sunglasses:
import {connect} from 'react-redux';
import result from 'lodash/result';
import getCurrentRouteName from 'react-navigation-current-route';
...
const currentRoute = getCurrentRouteName(this.props.navigationState)
...
export const mapStateToProps = (state) => ({
navigationState: result(state, 'nav', {}),
});
export default connect(mapStateToProps, null)();
import {call,select} from 'redux-saga/effects';
import result from 'lodash/result';
import getCurrentRouteName from 'react-navigation-current-route';
export const getNavigationState = (state) => result(state, 'nav', null);
export function* someSaga () {
const navigationState = yield select(getNavigationState);
const currentRoute = yield call(getCurrentRouteName, navigationState);
}
References: