D
D
danila_prokopenko2021-04-21 23:08:45
React
danila_prokopenko, 2021-04-21 23:08:45

Make a separate product page in React?

There is little knowledge of react, but you need to make a project. I work with mysql, I have already connected to the server, I get data from the table to the page. The essence of the question is: how to make it so that when you click on a product card, it opens in a new window with its data? What parameters, what to send where? I understand that you need to get the id and search for it in the entire array, but how to do it? In php, this is done by a href="....sime.php?id=<?= $elem['id'] ?>", and already on the product page, having connected to the database, we search by id, but as in react do it, I don't know.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
n1ksON, 2021-04-21
@danila_prokopenko

So far, only this solution comes to mind:
1. We hang an onClick event on the product card and do a redirect to a new page with the product id (example.com/catalog --> example.com/product/999)
2. We use react-router-dom and make Route c by /product.
3. In the component, we take the id from the url and load the data via the API.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question