react路由传参的几种方式

发送
1.params
     <li key={item.id}><Link to={`/home/message/detail/${item.id}/${item.titile}`}>{item.titile}</Link></li>
2. search
      <li key={item.id}><Link to={`/home/message/detail?id=${item.id}&title=${item.titile}`}>{item.titile}</Link></li>
3.state 
    <li key={item.id}><Link to={{path:'/home/message/detail',state:{id:item.id,titile:item.titile}}}>{item.titile}</Link></li>


声明
1.params 路由声明
<Route path="/home/message/detail/:id/:title" component={detail}/>
2.search 不用声明
<Route path="/home/message/detail/" component={detail}/> 
3.state 不用声明
<Route path="/home/message/detail" component={detail}/>


接受
1. const {params} = this.props.match
2.const {search} = this.props.location
3.const {id,titile} = this.props.location.state
上一篇:SMM整合配置模板


下一篇:input框 模糊搜索节流方法