Matt Saunders
Matt Saunders

Reputation: 4371

React Router v4 Redirect with parameters

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?

Upvotes: 6

Views: 14416

Answers (1)

Matt Saunders
Matt Saunders

Reputation: 4371

Resolved:

I had to wrap in curly braces like so:

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

(Thanks to Giri for guidance)

Upvotes: 13

Related Questions