In my current project, I must to implement different site behavior depending on whether it was a visit by a direct link or a redirect from a another pages of site trough a react-router.
So... is there a way to detect this fact?
In my current project, I must to implement different site behavior depending on whether it was a visit by a direct link or a redirect from a another pages of site trough a react-router.
So... is there a way to detect this fact?
You can use document.referrer
. The value is an empty string if the user navigated to the page directly (not through a link). Here is an example using React Hooks.
useEffect(() => {
if (document.referrer === "") {
console.log("User came directly");
} else {
console.log("User did not came directly");
}
})