get current path react router code example
Example 1: react get current route
import { useLocation } from 'react-router-dom';
const location = useLocation();
console.log(location.pathname);
Example 2: react current path
<Router path="/" component={Navigation} />
this.props.location.pathname
Example 3: get current url react router
import {withRouter} from 'react-router-dom';
const SomeComponent = withRouter(props => <MyComponent {...props}/>);
class MyComponent extends React.Component {
SomeMethod () {
const {pathname} = this.props.location;
}
}