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 }