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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容