To get the current router instance or current location you have to create a Higher order component with withRouter
from react-router-dom
. otherwise, when you are trying to access this.props.location
it will return undefined
Example
import React, { Component } from 'react';
import { withRouter } from 'react-router-dom';
class className extends Component {
render(){
return(
....
)
}
}
export default withRouter(className)