);
}
function ProductDetailPage() {
const { id } = useParams();
const product = products.find((p) => p.id === id);
if (!product) {
return
Product not found.
;
}
return (
{product.name}
${product.price}
);
}
function App() {
return (
} />
} />
);
}
export default App;
/*
Notes:
- useParams() reads the :id segment out of the URL as a string —
note product.id in the array is also a string ("1") so the
comparison in .find() lines up correctly.
- Each product's Link carries its own id into the URL, so
ProductDetailPage always knows exactly which product to show.
*/