1

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>
2

2 Answers 2

1

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}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks very much Alexander.
if you haven't declared you props in the render function (like this: const { id} = this.props; ) you would have to put in the url this.props.id instead of only id. If it works, make sure to set my answer as the good answer ;)
0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.