react使用hashHistory实现类似get方法带参数跳转

来源:互联网 发布:我的世界,java.net 编辑:程序博客网 时间:2024/06/05 17:42



主页router

<Route path="/apartmentReserve/:apartmentId" component={ApartmentReserve}/>


前一页引入hashHistory

import {hashHistory} from 'React-router'


传参:

btnClick:function () {    hashHistory.push({        pathname: '/apartmentReserve/'+yourApartmentId,        query: {            name:yourApartmentname,            price:yourApartmentprice        },    })}

或者通过<Link>to 传参

<Link to={          {              pathname:"/jump",              hash:'#ahash',               query:{foo: 'foo', boo:'boo'},               state:{data:'hello'}            }     } >点击跳转     </Link> 



后一页接收参数:

componentWillMount(){    apartmentData={
        apartmentId:this.props.params.apartmentId,
        name:this.props.location.query.name,        price:this.props.location.query.price    }}





主页router

<Route path="/apartmentReserve/:apartmentId" component={ApartmentReserve}/>
原创粉丝点击