react-router 跳转传参

2017-10-11  本文已影响1304人  JackfengGG

跳转传参

  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

上一篇下一篇

猜你喜欢

热点阅读