-
SummaryI'm trying to fetch data on the server side using getServerSideProps in a dynamic route like [slug].js. The data doesn't show up correctly on first load. Am I missing something? Any suggestions or examples would help! Additional informationNo response ExampleNo response |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
I ran into this too. If you're using getServerSideProps with a dynamic route like [slug].js, make sure the file is inside the pages directory (not the new app directory). Also, check that you're accessing context.params.slug properly. For me, the issue was that I forgot to return the data as props, so the page didn’t receive anything. Once I fixed that, it worked fine. |
Beta Was this translation helpful? Give feedback.
-
Great point — especially about the pages/ vs app/ directory! 🚀 Another common pitfall: if the API returns null or undefined, be sure to handle that with a notFound: true or a proper fallback UI to prevent rendering issues. |
Beta Was this translation helpful? Give feedback.
I ran into this too. If you're using getServerSideProps with a dynamic route like [slug].js, make sure the file is inside the pages directory (not the new app directory). Also, check that you're accessing context.params.slug properly. For me, the issue was that I forgot to return the data as props, so the page didn’t receive anything. Once I fixed that, it worked fine.