Next.js Discord

Discord Forum

getServerSideProps not working when navigating from one page to another using next/link

Unanswered
Segugio dell'Appennino posted this in #help-forum
Open in Discord
Segugio dell'AppenninoOP
- Migrating from NextJs 14 pages router to NextJs16 pages router

- This happens only in production
- When user refreshes the page, the orgId returned from getServerSideProps is present
- When user navigates to another page and comes back using <Link /> component, orgId and orgIdToo both are empty
- The same code was working properly in Nextjs 14.2.32 pages router

- Adding below the exact code I am using for testing and figuring this issue out
import { GetServerSidePropsContext } from "next";

import { Test } from "./test1";

export function getServerSideProps(
  context: GetServerSidePropsContext & { params: { orgId: string } }
) {
  const { orgId } = context.params;
  const orgIdToo = context.query.orgId;
  console.log("orgId test2 > ", orgId);
  console.log("orgIdToo test2 > ", orgIdToo);
  return {
    props: {
      data: "Hello World",
      orgId: orgId,
      orgIdToo: orgIdToo,
    },
  };
}

function Test({orgId,orgIdToo}:{orgId:string; orgIdToo:string}){
console.log(orgId, orgIdToo);
return <div className="">
      <div style={{ margin: "10px" }}>
        <Link href="/org/1">Org 1</Link>
      </div>
      <div style={{ margin: "10px" }}>
        <Link href="/org/2">Org 2</Link>
      </div>
    </div>
}

function OrgHome(props: { orgId: string; orgIdToo: string }) {
  return <Test orgId={props.orgId} orgIdToo={props.orgIdToo} />;
}

export default OrgHome;

0 Replies