0

On the first page, I do router.replace() with new a query. so the URL becomes similar to someUrl?timestamp=1000. After this I move to second page with router.push() and press back button on the browser, which takes me back to someUrl?timestamp=1000.

Now in getServerSideProps, I get empty query object. but if I refresh this page, I get the correct query object. My goal is to get query.timestamp (1000).

What's wrong with going back feature? The result is same with router.back().

export const getServerSideProps: GetServerSideProps<PrimaryPageProps> = async (
  context: GetServerSidePropsContext,
) => {
  console.log(context.query); // it returns {}
  const { timestamp } = context.query;
  return {
    props: {
      timestamp: timestamp === undefined ? null : Number(timestamp),
    },
  };
};

This is how I updated the query on the first page.

        <Btn
          onClick={() =>
            router.replace(router.pathname, {
              query: { timestamp: Date.now() },
            })
          }
        >
          Update query
        </Btn>
Gianna
  • 205
  • 2
  • 12

0 Answers0