Open bernhardreisenberger opened 6 years ago
Hi @bernhardreisenberger!
I am not expert on document.referrer
, but I thought this is only related to what page you came from? Not route changes on same domain. So if you came from google.com to the app, that would be the referrer. But route changes on same domain does not change document.referrer. Please prove me wrong here and I can learn something new :)
Example using Chromium:
document.referrer
to ""document.referrer
to "http://asdf.com/"document.referrer
to "http://forums.asdf.com/"document.referrer
to ""This means, route changes on same domain will be tracked with document.referrer
(not only subdomain, but path changes too), but only if that change was triggered via link. This is statet on https://developer.mozilla.org/en-US/docs/Web/API/Document/referrer
This results in route changes triggered via javascript, not being tracked by document.referrer
.
Anyhow, document.referrer
is read-only.
We could override the property using https://stackoverflow.com/a/23434948, but on the other hand, the specification does only state navigation via link,
although i do not know if they had navigation via javascript in mind at the time they wrote the specification for document.referrer
in 2003.
Nevertheless, in the (cerebral) addressbar code i have found a variable named prevUrl
. If i understand correctly, its use is to check if an url change should happen or not.
This variable prevUrl
could also be used to track the previous visited url.
In @cerebral/router a new function getPrevUrl()
could access the value via addressbar.prevUrl
That way, the @cerebral/router would always know the previous url visited.
What do you think of that idea?
@christianalfoni does that make sense? i can make a pull request, if you acknowledge.
Hi,
First of, i am using cerebral router for navigation. It would be neat, to access the referrer (previous visited url) from the current visited url. use-case1: i want to return to the previous site after clicking the save-button on a settings page.
use-case2: i want to show a message after clicking the save-button on a settings page.
While this is possible by saving the current location to state before going to example.com/settings, it would be easier if the new location just knows, where i came from. Using window.history.back() is not sufficient, because i only want to go back to the previous location in use-case1 Using document.referrer would be sufficient, but it is not possible, because navigation with the router will not change the document.referrer. Is this a desired behaviour?