美文网首页
react-router 跳转传参

react-router 跳转传参

作者: JackfengGG | 来源:发表于2017-10-11 10:50 被阅读1304次

    跳转传参

    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
    
    

    相关文章

      网友评论

          本文标题:react-router 跳转传参

          本文链接:https://www.haomeiwen.com/subject/nskbyxtx.html