dva-day2路由跳转

路由跳转(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>
    )}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值