How to generateMetadata without making two api calls. #68187
Replies: 8 comments 6 replies
-
In Next 13 and 14, because If not, you can still use |
Beta Was this translation helpful? Give feedback.
-
Try creating a class that will have 1) a method for fetching data with cache, 2) cache-property. In method check the cache. If it's empty, then call axios and get data. Save the data in cache. Next call of this method will prevent network request. Works as react.cache but DIY and in more controlled way. It's just an assumption |
Beta Was this translation helpful? Give feedback.
-
Avoiding using two requests may not seem reasonable in itself Our SEO for dynamic pages is also generated on the server based on a set of local rules to obtain merchant information. What you're saying is that SEO data and product data are separated. In my opinion, the best way is to merge them into one interface, which is more appropriate |
Beta Was this translation helpful? Give feedback.
-
Have you tried using |
Beta Was this translation helpful? Give feedback.
-
I have the same issue, in past, I used NextJS 11 and at that point it was simple but now for SEO calling 2 API it doesn't feel write. It doesn't matter if we use fetch or Axios it should work the same as it used to in Next 11. i checked remix docs and they are doing the same thing. i guess i need to go for a library like React Helmet or something similar to resolve this issue. |
Beta Was this translation helpful? Give feedback.
-
Yes @vishalnimbalkar55 In the pages router there is a component from 'next/head' it's works great no need to call two APIs from one API call we can utilize the same data but this is not available in the app router. |
Beta Was this translation helpful? Give feedback.
-
Does this work for you? https://nextjs.org/docs/app/building-your-application/caching#react-cache-function |
Beta Was this translation helpful? Give feedback.
-
I have the same problem. |
Beta Was this translation helpful? Give feedback.
-
In the dynamic route, we need to make two API calls: first to get the SEO data in the generateMetadata function and another in the component itself to get the page data.
Because it's a dynamic page, we cannot set a static title and description.
Previously, in the page router, there were components that we could use in the main component itself to generate the SEO data. However, this will not work in the App router.
I'm sure that other people are also facing the same issue.
If anyone knows the answer or has a solution for this, please share. I would be grateful.
Beta Was this translation helpful? Give feedback.
All reactions