-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Allows developers to add data to History.state #1658
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
Thanks for the proposal. |
Maybe I expressed badly, I mean passing the state to
It will passing |
for example: user's router is |
Distinguish in what way and what for? both will be the same route anyway? |
Because i want to distinguish the forward and backward behavior, if it is backward, i can restore page from cache, it is useful for mobile web app. for example: user is in so i add a key to distinguish the two route, they are not same. I develop vue-navigation to do this, but now the key only can put in url, i against put the key in the url too, so i want put key in history.state, like vue-router does.https://github.com/vuejs/vue-router/blob/dev/src/util/push-state.js#L50 |
Your message was, I shouldn't have used the word url 😆 . The url is actually a piece of state |
Thanks for such a quick reply. I still have some doubts, What is the difference with my opinion? I want to associate the url with the page cache. |
Actually, nothing prevents you from using that |
But vue-router's |
And there is no way to get |
use a query parameter, they are there for that: |
thanks, I'll try it |
So really the only way to re-hydrate using back/forward is to leverage Vuex, no way and no plans to ever have vue-router let us dump data into history like the native api? |
Is it safe to use the |
I would like to have the history state passed through as well. I have a situation wherein I'm using vue.js alongside a separate application, which uses the history state for some other things. However, because vue.js does not have access to the history state, i am limited by how i am able to reroute calls. I want to be able to use |
This would be very useful. I have very simple scenario: Imagine two categories of news items: Top News and Latest news, one is accessible through If I could store extra data to each location change I could add the current tab which news item was opened from. I tried to do it now, but it is very difficult to implement without having some kind of unique router step identification as same news item may appear multiple times in one user session. So currently I haven't found any workaround. |
@posva it is often desirable to not use a query parameter. A lot of UI state I don't want to keep in the URL. Query params are basically forever - once they're in use you'll have links to your site with them everywhere. Putting something like "user inputed text" or "selected colors" or "open accordions" in query params means that bookmarking that page will restore that. It also means you need to support those query params for much longer than the cycle of UI changes is likely to be. I do want to have state saved for locations, though. So where to put it?
Vuex doesn't solve this issue. |
I know this issue is two years old, but I thought in case someone stumbled upon this again, I could offer my workaround. I use beforeRouteLeave(to, from, next) {
history.replaceState({
...window.history.state,
search: this.search,
}, '')
next()
} ...and then retrieve it once the component mounts again. beforeMount() {
if (window.history.state.search) {
this.search = window.history.state.search
}
}, |
Locking as discussion is at #2243 |
What problem does this feature solve?
Some data is expected to be stored along with the browsing history, but I do not want the data to appear in the URL, so I hope I can save data to
History.state
.I am currently developing vue-navigation. To distinguish between different page instances of the same URL, I need to generate a unique
key
.At present,
key
stored in the url, see demo, but in vue-router's history mode, I hope that thekey
is transparent to the user.What does the proposed API look like?
Add
state
to route object, so the developer can choose to save the data toquery
orstate
.The text was updated successfully, but these errors were encountered: