Skip to content
Discussion options

You must be logged in to vote

Your code works for me. getInitialProps is called both on the server and then when navigating to this page via next/link it is called again (this time logged to my browsers console).

When navigating to this page via next/link, context.req is null therefore this conditional is executed: if (!context.req) { return { data: [] } }

As a further example:

index.getInitialProps = async context => {
  if (!context.req) {
    return { data: 'logs to the browser when navigated to client side' };
  }

  // on the server, this runs and logs to your terminal
  return { data: 'logs to the terminal when on the server' };
};

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@anagobabatunde
Comment options

Answer selected by jamesmosier
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants