how to get url in react code example
Example 1: how to get url in react
window.location.href
Example 2: 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;
}
}
Example 3: get data from url using react
this.props.match.params.id