美文网首页React相关前端
React-路由传递参数

React-路由传递参数

作者: 墨_梵 | 来源:发表于2018-11-05 14:14 被阅读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传的参数是公开的

    相关文章

      网友评论

        本文标题:React-路由传递参数

        本文链接:https://www.haomeiwen.com/subject/cersxqtx.html