I want to create a simple webshop. On the page "products" a list of all offered products will be listed. When clicking into one product I want to show the ID and the name of the product. However, I am only able to display the ID of the product since I am getting it from the URl. Is there a method to also get the name out of the list by having the id?
Products:
<script>
let products = [
{
id: 0,
name: "Superbike",
},
{
id: 1,
name: "Ultrabike",
},
];
</script>
<h1>Products</h1>
<ul>
{#each products as product}
<li><a href={"#/products/" + product.id}>{product.name}</a></li>
{/each}
</ul>
Product Details:
<script>
export let params = {};
$: id = params.id;
$: name = params.name;
</script>
<h1>Product Details</h1>
<p>Name: {name}</p>
<p>ID: {id}</p>
<p><a href="#/products/">Back to the list of products</a></p>
I got the ID from the URl and wanted to also get the name by the ID. However, I don't know how I might be able to do that.