heinst
heinst

Reputation: 8786

Accessing URL Parameters with React Router?

I read through the documentation and tutorial on URL Parameters in React Router and saw that you should be able to access the parameters in this.props.params. this.props.params is undefined in my render() function. My URL currently looks like this: http://localhost:8000/?color=green and I am trying to access the color value. Is this how you access the parameters or is there any other way to do this?

Upvotes: 1

Views: 264

Answers (1)

heinst
heinst

Reputation: 8786

To access a URL parameter using React Router, you would use this.props.location.query.color where color is the name of the URL parameter you want to get.

Upvotes: 1

Related Questions