Reputation: 351
I am trying to navigate using history push inside App.jsx. I have used below code for the same.
componentDidMount() {
if(!this.authService.isAuthenticated())
{
this.props.history.push('/Login');
}
}
But it is giving an error as history is undefined. I tried logging props object and I got the below output.
Please help me in navigating inside app.jsx.
Upvotes: 0
Views: 1962
Reputation: 5912
Export your component with withRouter
.
import withRouter.
import { withRouter } from 'react-router'
Export in your component like this.
export default withRouter(MyComponent)//your component name
Upvotes: 1