[英]this.props.history.push not working in react
I am trying to navigate using history push inside App.jsx. 我试图使用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. 请帮助我浏览app.jsx。
Export your component with withRouter
. 使用withRouter
导出组件。
import withRouter. 用路由器导入。
import { withRouter } from 'react-router'
Export in your component like this. 像这样导出您的组件。
export default withRouter(MyComponent)//your component name
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.