React 在非路由组件中实现编程式路由跳转
作者:互联网
import React from 'react';
//withRouter可以加工一般组件,让一般组件具备路由组件所特有的API
//withRouter的返回值是一个新组件
import { withRouter } from 'react-router';
class Header extends React.Component {
back = () => {
this.props.history.goBack()
}
render() {
return (
<div className="page-header">
<h2>React Router Demo</h2>
<button onClick={this.back}>回退</button>
</div>
)
}
}
export default withRouter(Header)
标签:react,withRouter,React,跳转,组件,import,路由 来源: https://blog.csdn.net/weixin_60463255/article/details/121589504