在过去的几个月里,我一直在使用react js,我刚刚了解了react的甜蜜警示引导插件。成功更新组件时,屏幕上会出现一个对话框。单击"click here“按钮后,history.push会被调用,它应该会路由到不同的页面,但我一直收到错误
未定义
history.push。
我在谷歌上搜索了相当多的东西,尝试了相当多的场景,但都没有成功。
代码片段:
class displayBlank extends Component {
render(){
<div id="displayDetails">
<DisplayDetails respData={this.state.respData} />
</div>
}
}
export default displayBlank;
class displayDetails{
handleUpdate()
{
// Body of HandleUpdate
swal({
title :"Customer Updated Successfully!",
icon : "success",
button: "Click Here!",
}).then((e) => { history.push('/blank');
});
}
render(){
<table>
<tr>
<td>
Table-Grid Contents
</td>
</tr>
</table>
<td>
<FormGroup controlId="formControlsDisabledButton" style={buttonalignment}>
<Button className="float-right" bsStyle="primary" type="submit" onClick={this.handleUpdate}>Save</Button>
{' '}
<Button className="float-right" bsStyle="primary" type="submit" disabled>Download</Button>
{' '}
</FormGroup>
</td>
}
}
发布于 2018-12-11 05:37:44
如果您使用的是react-router,请使用this.props.history.push('<url>')
。
如果遇到Cannot read property 'push' of undefined
错误,请将组件包装在withRouter中
import { withRouter } from 'react-router';
class DisplayBlank extends Component {
...
}
export default withRouter(DisplayBank);
发布于 2021-12-07 05:48:15
您好,如果您面临的问题是
react js中的
history.push试试这个
import { useNavigate } from "react-router-dom";
const history= useNavigate();
history("/path");
发布于 2021-03-22 02:31:58
您只需在函数参数中将props
的history
作为对象传递即可。
function =({history})=>{
return <div>Hello</div>;
}
https://stackoverflow.com/questions/53712860
复制相似问题