react路由传参

父组件

  class userC extends React.Component{

    handleClick(v){

      this.props.history.push(`/chat/${v.user}`)

    },

    render(){

      return(

        <Card onClick={v=>this.handleClick(v)}></Card>

      )

    }

  }

路由这样写

import chat from '/chat';

...

  <Route path='/chat/:user' component={chat} ></Route>

...

子组件这样写

  

class chat extends React.Component{

    render(){

      return(

        <h2>chat with user:{this.props.match.params.user}</h2>

      )

    }

  }

  

笔记,仅供参考

猜你喜欢

转载自www.cnblogs.com/wenbodeboke/p/10019207.html