import { Component } from 'react'
import { Link } from 'react-router-dom'
import { withRouter } from 'react-router-dom'
//使用withRouter方法 才能进行this.props.history.push("") 跳转
export default withRouter(
class home extends Component {
state = {
}
render() {
return (
<div>
<div>
{/* 使用Link 进行跳转 */}
<Link to="/about" >about</Link> <Link to="/apple">apple</Link> <Link to="/blane">blane</Link>
</div>
<button onClick={this.goapple.bind(this)}>跳转到user</button>
<div>{this.props.children}</div>
</div>
)
}
goapple() {
//编程式导航
console.log(this.props);
this.props.history.push("/user");
}
}
)
返回上一级路由
this.props.history.goBack()