1import { useLocation } from 'react-router-dom'
2
3function HeaderView() {
4 const location = useLocation();
5 console.log(location.pathname);
6 return <span>Path : {location.pathname}</span>
7}
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}