React - How to get parameter value from query string?

后端 未结 30 2204
温柔的废话
温柔的废话 2020-11-22 10:22

How can I define a route in my routes.jsx file to capture the __firebase_request_key parameter value from a URL generated by Twitter\'s single sign on process a

30条回答
  •  闹比i
    闹比i (楼主)
    2020-11-22 10:46

    I had a hard time solving this issue. If none of the above work you can try this instead. I am using the create-react-app

    Requirements

    react-router-dom": "^4.3.1"

    Solution

    At the location where router is specified

    
    

    Add the parameter name that you would want to pass in like this

    
    

    At the page where you are rendering some/path you can specify this to view the parameter name call id like this

    componentDidMount(){
      console.log(this.props);
      console.log(this.props.match.params.id);
    }
    

    At the end where you export default

    export default withRouter(Component);
    

    Remember to include import

    import { withRouter } from 'react-router-dom'
    

    When console.log(this.props) you would be able what has been passed down. Have fun!

提交回复
热议问题