Getting query parameters from react-router hash fragment

后端 未结 9 1564
心在旅途
心在旅途 2020-12-04 11:55

I\'m using react and react-router for my application on the client side. I can\'t seem to figure out how to get the following query parameters from a url like:



        
9条回答
  •  抹茶落季
    2020-12-04 12:19

    OLD (pre v4):

    Writing in es6 and using react 0.14.6 / react-router 2.0.0-rc5. I use this command to lookup the query params in my components:

    this.props.location.query
    

    It creates a hash of all available query params in the url.

    UPDATE (React Router v4+):

    this.props.location.query in React Router 4 has been removed (currently using v4.1.1) more about the issue here: https://github.com/ReactTraining/react-router/issues/4410

    Looks like they want you to use your own method to parse the query params, currently using this library to fill the gap: https://github.com/sindresorhus/query-string

提交回复
热议问题