Let's say I'm in Page A(/path-a
) and I go to page B(/path-b
).
Afterwards, I click the "previous page" button in the browser.
In this case, how should I get the value of /path-b
in PageA.tsx
?
Update
I am using react-router-dom
Let's say I'm in Page A(/path-a
) and I go to page B(/path-b
).
Afterwards, I click the "previous page" button in the browser.
In this case, how should I get the value of /path-b
in PageA.tsx
?
Update
I am using react-router-dom
Assuming you want a vanilla JS solution:
You can use document.referrer
. This will give you the url you come from,
in the new page.
For more information you can see this link
Assuming you want a React Router Dom solution:
This SO's answer from another post explains really well how to do it