Querystring in react-router

后端 未结 2 1783
小蘑菇
小蘑菇 2021-02-07 00:39

I am trying to set a Route path with a query string. Something in the lines of:

www.mywebsite.com/results?query1=:query1&query2=:query2&query3=:query3
         


        
2条回答
  •  时光说笑
    2021-02-07 01:06

    If you are using React Router v2.xx, you can access the query parameters via the location.query object passed in to your Route component.

    In other words, you could rework your route to look like the following:

    
    

    And then inside your SearchResults component, use this.props.location.query.query1 (similar for query2 and query3) to access the query parameter values.

    EDIT: This is still the case for React Router v3.xx.

提交回复
热议问题