【发布时间】:2021-09-03 13:20:52
【问题描述】:
我正在尝试通过单击按钮导航到其他页面,但是说 can not read property push of undefined. 会引发错误
我对用于功能组件的history进行了一些研究。
我如何利用类组件中的历史记录或其他方式(反应方式)来导航其他页面。
这是我的代码。
import React, { Component } from 'react';
class CentralBar extends Component {
constructor(props){
super(props)
this.state = {
}
this.someText = this.someText.bind(this);
}
someText(){
this.props.history.push(`/login/`);
}
render() {
return (
<div className="crentralPanel">
<button type="button" class="btn btn-light " onClick={this.someText}>Click on Text</button>
</div>
);
}
}
export default CentralBar;
【问题讨论】:
标签: javascript reactjs react-router