red
red

Reputation: 1619

How to get reactjs router hardcoded params

I have the following route:

<Route path="/userstream/:user" component={ Profile } param="stream" />

Then in my component i get :user in this way: this.props.match.params.user

But, how I can get stream from hardcoded param?

Thank you in advance.

Upvotes: 2

Views: 613

Answers (1)

Clarity
Clarity

Reputation: 10873

One way would be to pass it as a prop to component:

<Route path="/userstream/:user" component={ (props) => <Profile {...props} param="stream" /> }  />

Edit: for completeness sake, it's worth to mention a second approach, which is to use a render prop:

<Route path="/userstream/:user" render={ (props) => <Profile {...props} param="stream" /> }  />

There are some performance differences between the two approaches: react router difference between component and render.

Upvotes: 5

Related Questions