Socket
Socket
Sign inDemoInstall

react-navigation-current-route

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-navigation-current-route

Get current route from react-navigation routes


Version published
Maintainers
1
Install size
87.3 kB
Created

Readme

Source

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:
/* Get current route in a container */

import {connect} from 'react-redux';
import result from 'lodash/result';
import getCurrentRouteName from 'react-navigation-current-route';
...
// Pass the current navigation state object
const currentRoute = getCurrentRouteName(this.props.navigationState)

...
// Get the current navigation state from the redux store
export const mapStateToProps = (state) => ({
  navigationState: result(state, 'nav', {}),
});

export default connect(mapStateToProps, null)(/* component-name*/);
/* Get current route in a middleware like saga */

import {call,select} from 'redux-saga/effects';
import result from 'lodash/result';
import getCurrentRouteName from 'react-navigation-current-route';

// Get the current navigation state from the redux store
export const getNavigationState = (state) => result(state, 'nav', null);

export function* someSaga () {
    const navigationState = yield select(getNavigationState);
    // Pass the current navigation state object
    const currentRoute = yield call(getCurrentRouteName, navigationState);
    // currentRoute would then have the current route name  
}

References:

Keywords

FAQs

Last updated on 24 Sep 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc