the context from getStaticProps is undefined.
If I console.log the context I get:
{ locales: undefined, locale: undefined }
I need the information from the url... If I try the same with getServerSideProps it is working. I'm using apollo with nextjs like the example: https://github.com/vercel/next.js/tree/canary/examples/with-apollo
export async function getStaticProps(context) {
const apolloClient = initializeApollo();
await apolloClient.query({
query: PAGE,
variables: variables,
});
console.log(context);
// { locales: undefined, locale: undefined }
// !!! need the info from the URL !!!
return {
props: {
initialApolloState: apolloClient.cache.extract(),
},
revalidate: 1,
};
}
Thx for any help.
These params doesn’t exist on the context Object that’s why you get undefined. I assume that you pass them as query parameters to the url. In that case you can get them from the context query param like this:
const { locales } = context.query
Read more about the params of the context Object in the next docs
https://nextjs.org/docs/api-reference/data-fetching/getInitialProps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With