How can I get a variable from the path in react router?

There is a new api in react-router-dom 5.1

https://github.com/ReactTraining/react-router/releases/tag/v5.1.0

import {useParams} from "react-router-dom";

function MyComponent(){
    const {date} = useParams()
}


In your initial component, set the path that loads your route. By adding /:date to the end of your route, that string can be accessed by calling props.match.params.date inside that routes component.

<Route exact path="/meeting/:date" component={DateComponent} />

In the component that the route renders, use props.match.params.date to access your string from path

Class DateComponent extends React.Component{
  render(){
    return(
      <h2>{this.props.match.params.date}</h2>
    )
  }
}

https://reacttraining.com/react-router/web/api/match