For example, a page has a modal component. The content in the modal component is written in the subcomponent (ModalDetail). This.props.location cannot be obtained in this component. Please answer. In addition to passing it in from the parent component and passing it through Is there any other way to get the window object?
Versions before
react-router v4 had a higher-order component called
withRouter
. You just need to wrap one layer when defining your own modal component.After wrapping a layer of withRouter, you can access the attributes you want. You can also study further to see what is inside.
You can also use withRouter and get it through this.props.location