2

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.

Clarity
  • 10,125
  • 2
  • 22
  • 32
red
  • 1,424
  • 9
  • 26

1 Answers1

5

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.

Clarity
  • 10,125
  • 2
  • 22
  • 32