React相关前端

React-路由传递参数

2018-11-05  本文已影响8人  墨_梵

react-router-dom 路由跳转传递参数


方式一

==通过query==
HTML方式
      <Link to={{ pathname: ' /user' , query : { day: 'Friday' }}}>
      
JS方式
    this.props.history.push({ pathname : '/user' ,query : { day: 'Friday'} })

获取参数
    this.props.location.query.day

方式二

==通过state==
HTML方式
      <Link to={{ pathname : ' /user' , state : { day: 'Friday' }}}>
      
JS方式
    this.props.history.push({ pathname:'/user',state:{day : 'Friday' } })

获取参数
    this.props.location.state.day

区别:

同query差不多,只是属性不一样,而且state传的参数是加密的,query传的参数是公开的

上一篇 下一篇

猜你喜欢

热点阅读