Next.js Discord

Discord Forum

Problem with accessing dynamic pages in prod

Unanswered
Orange-tailed bumble bee posted this in #help-forum
Open in Discord
Orange-tailed bumble beeOP
I have a NextJS site with multiple dynamic pages. I'm using getServerSideProps to get the query name and then I use the name to fetch data from an API.

Here's my code:
export function getServerSideProps(context: GetServerSidePropsContext) {
  const { name } = context.query;
  return {
    props: {
      name,
    },
  };
}


In local everything works.
In prod it works only if I enter the URL of the dynamic page directly but if I try to access the page from the static page and click the link to the dynamic page it returns undefined instead of the name.

Here's a link:
<Link
  href={{
    pathname: `/pokemon/[name]`,
    query: { name: p?.name },
   }}
   key={p.name}
>


I don't understand why it's not working.

0 Replies