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>
)
}
}
筆記,僅供參考
轉(zhuǎn)載于:https://www.cnblogs.com/wenbodeboke/p/10019207.html
總結(jié)
- 上一篇: QQ音乐:React v16 新特性实践
- 下一篇: TDD容易被忽略的五大前提