React - How to get parameter value from query string?

后端 未结 30 1999
温柔的废话
温柔的废话 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条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 10:53

    If you aren't getting the this.props... you were expecting based on the other answers, you may need to use withRouter (docs v4):

    import React from 'react'
    import PropTypes from 'prop-types'
    import { withRouter } from 'react-router'
    
    // A simple component that shows the pathname of the current location
    class ShowTheLocation extends React.Component {
      static propTypes = {
        match: PropTypes.object.isRequired,
        location: PropTypes.object.isRequired,
        history: PropTypes.object.isRequired
      }
    
      render() {
        const { match, location, history } = this.props
    
        return (
          
    You are now at {location.pathname}
    ) } } // Create a new component that is "connected" (to borrow redux terminology) to the router. const TwitterSsoButton = withRouter(ShowTheLocation) // This gets around shouldComponentUpdate withRouter(connect(...)(MyComponent)) // This does not connect(...)(withRouter(MyComponent))

提交回复
热议问题