I have a Javascript function that fetch dynamic random recipes from spoonacular API and then append some HTML to an Element, the HTML includes dynamic links HREFs, if one is clicked it will go to dynamic route, such as www.example.com/recipe/782585 (depends on the ID value)
const spoonacular = async () => {
const response = await fetch(
"https://api.spoonacular.com/recipes/complexSearch?apiKey=c0c692d2b8be4e92a29883049789419b&includeNutrition=true.",
{
method: "GET",
headers: {
"Content-Type": "application/json",
},
}
);
const data = await response.json();
data.results.forEach((e) => {
const html = `
<div class="dish" id="a${e.id}">
<a href="recipe/${e.id}"><img src=${e.image} alt="" class="dishImg" /></a>
<h2 class="dishTitle">
${e.title}
</h2>
</div>
`;
dishes.insertAdjacentHTML("afterbegin", html);
});
};
spoonacular();
the plan here is to make dynamic component recipe.html that will send request to spoonacular with the ID param and get informations about the recipe like ingredients and instructions..etc, now this looks easy using some JS libraries like react, but can I do that without using any Library or backend routing?
reactwe can make dynamic routes using react-router-dom, e.g.<Route path="/:component" element={<ComponentContainer />}></Route>then we can makeLinkto that route with dynamic parameter :<Link to="/employees">, then we can useuseParamsto get the parameter value, i want to do the same thing but without usingreact