热门搜索 :
考研考公
您的当前位置:首页正文

react-router 跳转传参

来源:东饰资讯网
  1. Link跳转
<Router history={history}>
    <Route path="messages/:query" component={Message} />
</Router>

============================================

<Link to={{pathname: `/messages/{param}` activeClassName="active">
    <img src={rowData.goodsImages} style={styles.goodImage}/>
</Link>

参数获取 this.props.params.query
<Router history={history}>
    <Route path="GoodsDetail" component={GoodsDetail} />
</Router>

============================================

<Link to={{pathname: "/GoodsDetail", query:{goodsId: rowData.goodsId} }} activeClassName="active">
    <img src={rowData.goodsImages} style={styles.goodImage}/>
</Link>

参数获取 this.props.location.query
  1. history跳转
browserHistory绝对路径
hasHistory相对路径

<Router history={history}>
    <Route path="UserOrderLogistics" component={User_OrderLogistics} />
</Router>

============================================

gotoHomeView() {
    this.props.homePressDown();
    hashHistory.push({
        pathname:'/UserOrderLogistics',
        query:{ship_no:ship_no,ship_id:ship_id}
    });
}

参数获取 this.props.location.query
  1. IndexLink
<Router history={history}>
    <Route path="/" component={App}/>
</Router>

============================================
如果链接到根路由/,不要使用Link组件,而要使用IndexLink组件

    <IndexLink to="/" activeClassName="active">
      Home
    </IndexLink>

或者使用hasHistory

Top