Shashika Virajh
Shashika Virajh

Reputation: 9457

React passing parameters with URL

Im developing a React application. When the user clicks on the view-button on a list view, I want that to be redirected to the view page with the item_id. I tried to use the hyperlink (< a> tag) tag to do this but it doesnt navigate with item_id of the clicked row. I want to know how to pass parameters with URL in react.

This is the code I tried.

 <a className="btn btn-info btn-xs" href={'/#/fld-view/:id'} title="View"><span className="glyphicon glyphicon-eye-open" aria-hidden="true"></span></a>

Upvotes: 1

Views: 5574

Answers (2)

user8424887
user8424887

Reputation: 1

Instead of use the <a> tag use the <Link></Link> tags from react-router

<Link to={
      {
        pathname: match.url + '/view',
        search:'? itemview1=' + id_1  
       }
  }>GO TO A VIEW</Link>

Upvotes: 0

Alexandre Rivest
Alexandre Rivest

Reputation: 694

Component Link from react-router would be the solution. Also, to add the props (in your case the id) to a string, you should go this way :

href={`/#/fld-view/${id}`} //ES6 or ES7 if I remember

if you aren't using it :

href={'/#/fld-view/' + id}

Upvotes: 1

Related Questions