calling GET apis inside app/api folder from nested pages client components /app/category/page.tsx
Answered
hareshFF posted this in #help-forum
hareshFFOP
im calling fetch(/api/search?q=pink) from a client component using useeffect, when done from a root page all is fine, but when same component is in a page which is a dynamic route inside category folder, nextjs auto prefixes the api url with category/api/search. Please help me remove this "category/" and just gave "api/search".
Answered by hareshFF
ok. i just had to add "/" at the beginning. found answer in stackoverflow(https://stackoverflow.com/questions/72951894/how-to-dynamically-fetch-api-route-from-component-in-page-folder)
1 Reply
hareshFFOP
ok. i just had to add "/" at the beginning. found answer in stackoverflow(https://stackoverflow.com/questions/72951894/how-to-dynamically-fetch-api-route-from-component-in-page-folder)
Answer