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
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM