天天看点

react路由跳转传递第二个参数并获取

路由跳转this.props.history.push('');

export default class IndexView extends React.Component {
  route = () => {
    this.props.history.push('/my/login',{
      data:111
    });
  console.log("跳转成功!");
  }
  render() {
    return (
      <div>
        <Contextmy></Contextmy>
        <input type = "button" onClick = {() => {this.route()}}  value = "登录"/>
      </div>
    )
  }
}
           

/my/login.jsx页面:

render() {
    console.log(this.props.location.state.data);
    return (
      <div>
        <p>欢迎登录</p>
      </div>
    )
  }
           

打印结果:

react路由跳转传递第二个参数并获取
react路由跳转传递第二个参数并获取