-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Should router.referrer store the previous page? #883
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I would agree this is very useful and alot of use cases. Had this scenario previously on a micro application that would reroute upon finishing. |
Probably also useful to determine weither to use a "forward" or "backward" transition - if the new path is the same as the referrer, user probably clicked the back button, so we want to use a "backward" transition, e.g. For that, the referrer would have to be updated after the route switch has been completely done. |
@LinusBorg Ohh, I didn't even think of that. That's nice. |
user probably clicked the back button Not enough to determine weither to use a "forward" or "backward" transition |
Weither or not that is enough depends on the developers intend for this part of his app. And it's better than nothing, considering that there simply is no way to detect a back-button click 100%reliably. Browser APIs don't reveal that info. |
this is very useful,I search the method so I find this issue. |
Are there any workarounds in meantime? |
This would definitely be a useful addition in 3.0. If there are any recent alternatives for inspecting the previous route, they'd be super valuable. |
I think the user history is just the history, not the route structure at all. The history is a line but the route structure under the line is like a tree or even more complicated net. |
Perhaps this solution is not perfect (because of global variable usage), but it works fine for me. Obviously, you can edit the |
I needed this feature again, so I made this simple Vue plugin. |
@mitar Thank you so much for this eligant mixin! I was kind of surprised something like this wasn't already in the router-core. |
Still looking for |
I added this hacky solution in our Nuxt project: router.beforeEach((to, from, next) => {
if (process.client) {
Object.defineProperty(
document,
'referrer',
{
configurable: true,
get: () => {
return from.name
? window.location.origin + from.path
: ''
},
}
)
}
next()
}) |
This would be also helpful to determine if a user has just visited the website or already navigated within. For example a back button would navigate to the landing page if the previous route isn't set or to the previous page if it is. |
There are times when it's useful to peek at what the previous page was. With normal page navigation,
document.referrer
stores the previous URL, but the HTML5 History API doesn't update that value unfortunately. 😞 Would it be desirable to access the referrer onrouter.referrer
? The getter might look something like this:As you can see, this would also require keeping a stack of previous pages, maybe just 1 level deep by default. Later, perhaps an option could be added to specify the max stack height.
The text was updated successfully, but these errors were encountered: