6

I have a route set up:

<Route path="/search/:name" component={foo} />

In a component I am trying to redirect based on the entered name:

<Redirect to="/search" />

I want to pass this.state.name to the Redirect, like /search/name. How?

B--rian
  • 5,578
  • 10
  • 38
  • 89
Matt Saunders
  • 4,073
  • 7
  • 33
  • 47

1 Answers1

13

Resolved:

I had to wrap in curly braces like so:

<Redirect to={"/search/" + this.state.name} />

(Thanks to Giri for guidance)

Matt Saunders
  • 4,073
  • 7
  • 33
  • 47
  • 4
    No problem!. I see you got confused a bit while I was using backticks instead of quotes. Sorry about that!. But avoid these kind of string concatenation wherever possible by using the backticks. For more info, [Have a look at this](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Template_literals) – Giri Jul 28 '17 at 12:47