React get current url parameters




Hello Friends,

We are generally use react route in our project. React router is so popular because of it is vary easy to use. Now you have question how to get react router parameters in component. you define params in router then it get in component render method. how to get url value in react js router V4. if you want to get slug from router then follow this example.

The categoryId is the URL parameter and it can be accessed in the component of the route. then how to get categoryId in CategoryComponent.

Define Route

<Route path="/category/:categoryId" component={CategoryComponent} />

Parameter Get In Component

class CategoryComponent extends React.Component{


let categoryId = this.props.match.params.categoryId;

// here do your code



I hope it can help you...