方法一:
路由的history对象:(前提是只对路由管理着的页面有效)
我们直接在页面中打印this.props,
export default class City extends React.Component{
render(){
console.log(this.props)
return(
<div>
<CityHeader title="城市选择" history={ this.props.history}/>
</div>
)
}
}
如下图,可以看到push和replace方法;
方法二:
window的history对象:
export default class Header extends React.Component {
backHandler = () =>{
window.history.back(); // 返回
}
PS:①this.props.history.push("/")----记录每次的效果,点击回到进来的页面;