Arasto
Arasto

Reputation: 491

How to add State in React-router

When pressing the icon i want my application to navigate me to localhost:8080/editrevision+700 (700 being the id of that specific item)

<Menu.Item className="edit" 
   as={Link} 
   to="/editrevision" + {revisionItem.id}> 
   <i className="far fa-edit"/> 
</Menu.Item>

i keep getting syntax error on this, all suggestions are very appreciated.

Upvotes: 0

Views: 73

Answers (1)

reisdev
reisdev

Reputation: 3403

The problem is the syntax of the to. You should wrap the whole value in curly braces.

The best way to pass id a parameter is as /editrevision/700. And, when you set the route, set its path as /editrevision/:id. The id can be retrieved through this.props.match.params.id.

<Menu.Item className="edit" 
   as={Link} 
   to={"/editrevision" + revisionItem.id}
   > 
       <i className="far fa-edit"/> 
</Menu.Item>

Upvotes: 3

Related Questions