0

I am currently trying to find the page that the user has came from to enter this current one in the server side props, im not sure if thats possible? or are there any ways that i could access that

TLDR: get the url which user is coming from and not where is going to, example:

coming from: http://localhost:6060/product/id/55555-62/

going to: http://localhost:6060/products/

I would like to access the id query, in the /products/ getServerSideProps

export const getServerSideProps = wrapper.getServerSideProps(store => async ({ req }) => {
  console.log(req);
 

  return {
    props: {},
  };
});
kaster
  • 1
  • 2

2 Answers2

0

https://nextjs.org/docs/api-reference/data-fetching/get-server-side-props#context-parameter

resolvedUrl: A normalized version of the request URL that strips the _next/data prefix for client transitions and includes original query values.

export const getServerSideProps = (ctx) => {...}

Inside ctx you can find params, query, resolvedUrl etc

m4china
  • 230
  • 3
  • 9
0

Would the referrer enough for the thing you needed it for?

req.headers.referer

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referer

Warren Mira
  • 242
  • 1
  • 7