How to pass parameters through the Link in React?

Asked

Viewed 12 times

-1

How to pass a parameter using Link?

In case I want to pass inside the Link the ID of my product to recover this value in my other component.

But in the to="" i can’t pass the value in JSX.

In case I wanted it to stay that way:

<Link className="btn btn-warning" to="/editalivro/:{lista.id}">Editar</Link>

I tried using crase, but it does not work to only accepted "".

How can I pass this value via param?

1 answer

1

Just add {} keys in the to and concatenate that solved.

<Link className="btn btn-warning" to={"/editalivro/" + lista.id}>Editar</Link>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.