Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to know the current route in react class component

/*For class based components*/
import { withRouter } from 'react-router-dom';

class SomeComponent extends Component {
  render() {
    console.log(this.props.location)
    console.log(this.props.location.pathname)
    console.log(this.props.location.match)
    return <div>Something</div>
  }
}

export default withRouter(SomeComponent)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #current #route #react #class #component
ADD COMMENT
Topic
Name
5+6 =