路由组件:
路由组件里面是有this.props的。
路由组件:
import React, { Component } from 'react';
import UserUI from '../components/userUI'
class UserPage extends Component{
handlerBack = () =>{
console.log(this.props);
this.props.history.push('/')
}
render(){
return(
<div>
我是user页
<button onClick={this.handlerBack}>回首页</button>
<UserUI></UserUI>
</div>
)
}
}
export default UserPage;
UI组件:
UI组件里面的this.props是空的,如果要使用的话,需要使用router提供的withRouter组件来完成,也就是要使用一个高阶组件。
UI组件栗子:
import React, { Component } from 'react'
import {withRouter} from 'dva/router'
class UserUI extends Component{
handlerBack = () =>{
console.log(this.props)
this.props.history.push('/')
}
render(){
return(
<div>
userUI组件
<button onClick={this.handlerBack}>返回首页 ---ui</button>
</div>
)
}
}
export default withRouter(UserUI);
觉得对自己有帮助就点个赞?呀。
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。