react页面间传递参数

react-router页面跳转,带请求参数

this.context.router.push({pathname:'/car_datail',state:{item:"hello"}});

pathname为跳转页面路径,可将跳转时要传递的参数放入state中

在第二个页面使用this.props.location.state得到上一页面传递参数

 

react-router v4中:

this.context.router.history.push()

 

import React, { Component, PropTypes } from "react";

export default class Home extends React.Component {
  toAbout = () => {
    this.context.router.history.push('about');
  }
  render() {
    return (
      <div>
        <div>Home</div>
        <div onClick={this.toAbout}>click to about</div>
      </div>
    );
  }
}

Home.contextTypes = {
  router:React.PropTypes.object.isRequired
}

 

posted @ 2016-10-19 09:46  ximi007  阅读(9703)  评论(0编辑  收藏  举报