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.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.