React-路由传递参数

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传的参数是公开的

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。