【问题标题】:How to get url Param in React如何在 React 中获取 url 参数
【发布时间】:2020-12-22 05:19:26
【问题描述】:

spring_page 有 human_number,这些数据将是基于 react_pages 的需求数据 所以我想将human_number 发送到react_page

<spring_page>       <react_page>
localhost:8080  ==> localhost:3000 

现在我通过使用 url 直接发送数据来做到这一点 在 spring_page -> 调用 localhost:3000/human_number 并且反应使用获取human_number参数

所以数据说得太清楚了。我想隐藏 human_number Like POST_method [post_param] 我对 REACT 很陌生,所以这可能是一个非常愚蠢的问题,或者我走错了路 我该如何解决这个问题?

【问题讨论】:

    标签: reactjs redirect post routes


    【解决方案1】:

    如果你使用 react-router-dom,你可以传递 url 参数,你也可以从你自己的组件访问参数。你必须给出冒号(:),然后是你的 id

      <Route path={`${path}/:topicId`} component={Demo} />
    
    
     const Demo =({match}) => {
     console.log(match.params.id)
    }

    【讨论】:

      【解决方案2】:

      在您的第一个组件中,您可以触发链接或按钮的此 onCick

      browserHistory.push({
          pathname: `/about`,
          search : 'param_here'
          state: {
              type: 'type'
          }
      });
      

      在您的其他组件中,您现在可以像这样抓取它们:

      constructor(props) {
          super(props);
          this.state = {
              search: props.location.search,
              type: props.location.state.type
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2023-02-21
        • 2021-09-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-09-30
        • 2016-02-03
        • 2020-05-02
        相关资源
        最近更新 更多