路由跳转(components/Product.jsx:使用的都是类组件Product)
1.Link跳转(视图中)
import {Link} from 'dva/router'
render(){
return (
<div><Link to='/'>去首页</Link></div>
)}
2.事件跳转(history对象中的push方法跳转)
1.withRouter拿到this.props.history对象
import {withRouter} from 'dva/router';
clickGoToHandler=(e)=>{
//console.log(this.props.history);
this.props.history.push('/')
}
render(){
return (
<div><button onClick={this.clickGoToHandler}>去首页</button></div>
)}
export default withRouter(Product)
2.routerRedux
import {routerRedux} from 'dva/router';
clickGoToReduxHandler=(e)=>{
this.props.dispatch(routerRedux,push('/'))
}
render(){
return (
<div><button onClick={this.clickGoToReduxHandler}>去首页</button></div>
)}