1/*In the 5.1 release of react-router there is a hook called useLocation,
2which returns the current location object.
3This might be useful any time you need to know the current URL.*/
4import { useLocation } from 'react-router-dom';
5
6const location = useLocation();
7console.log(location.pathname);
8
9
1import {withRouter} from 'react-router-dom';
2
3const SomeComponent = withRouter(props => <MyComponent {...props}/>);
4
5class MyComponent extends React.Component {
6 SomeMethod () {
7 const {pathname} = this.props.location;
8 }
9}