I have tried to create an authenticated route component to wrap my react routes which redirects to '/' path if login is not valid. I was following this answer: https://stackoverflow.com/a/43171515/6716062
However I would like to access my redux store. How can I access the loginStatus prop which I want to inject into props? With the following code props.loginStatus is undefined
Thanks
import React from 'react';
import { Route, Redirect } from 'react-router-dom';
import { SUCCESS } from '../common/webUtils';
import { connect } from 'react-redux';
function AuthRoute( {component: Component, ...rest} ) {
return (
<Route
{...rest}
render={ (props) => props.loginStatus === SUCCESS
? <Component {...props} />
: <Redirect to={{pathname: '/', state: {from: props.location}}} />}
/>
)
}
function mapStateToProps( state ) {
return {
loginStatus: state.userReducer.loginStatus
}
}
export default connect( mapStateToProps )( AuthRoute );