Let's say there are three pages - A, B, and C.
I can navigate from A to C and from B to C as well, but the view of C depends on the page from which we are navigating.
I would like to know how we can identify in Next.js from which page we are routing to page C.
Page C has a dynamic route
TIA
You could pass the previous location as query data:
<Link
href={{
pathname: "/some-page",
query: "current location", // the data
}}
>
<a>Some Text</a>
</Link>
Then you can retrieve the query data:
const router = useRouter();
const data = router.query;
If you don't like the idea of passing the previous location as a query, you could save the current location in a global state, like Redux on a page mount, after reading the previous value, which represents the previous location pathname.