Skip to content
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

Add custom data to barba.history #630

Closed
Tracked by #703
johnrobertcobbold opened this issue Jun 23, 2021 · 4 comments
Closed
Tracked by #703

Add custom data to barba.history #630

johnrobertcobbold opened this issue Jun 23, 2021 · 4 comments
Assignees
Milestone

Comments

@johnrobertcobbold
Copy link

johnrobertcobbold commented Jun 23, 2021

It seems to be not possible to add custom data to the barba.history using pushState as the state gets overwritten by barba.js own data. There is currently no methods provided to do that.

browse to any page
push some data

window.history.pushState('{"random_data":1}', '', `?new_random_state`);

check that data is there:

history.state
"{\"random_data\":1}"

click on any link
click on previous button
check history.state;

history.state

we lost all data previously added and history.state just contains other barba.js data:

{from: "barba", index: 0, states: Array(1)}
@xavierfoucrier xavierfoucrier self-assigned this Jun 29, 2021
@xavierfoucrier xavierfoucrier changed the title add random data to history / pushState Add random data to history / pushState Jun 29, 2021
@xavierfoucrier
Copy link
Member

xavierfoucrier commented Jun 29, 2021

Hello @goyavo,

This is the intended behavior.
Barba uses pushState to manage internal page history.

What's the goal of pushing random data into the window history here? 🤔

@johnrobertcobbold
Copy link
Author

johnrobertcobbold commented Aug 28, 2021

What's is the goal of pushing random data into the window history here? 🤔

Thanks for answering and apologies, I somehow completely missed the reply notification.

Perhaps the expression "random data" is misleading, we were thinking of specific things related to the state of the page like:

the tab that was open on that page
the product that was clicked when leaving the page
etc

basically any kind of state data which could normally be pushed in window.history and then retrieved on load to restore the previous state of the page. Currently everything is being overwritten by barbajs.

@xavierfoucrier
Copy link
Member

@goyavo OK I understand what you mean 👍

May be at least it would be better that Barba store their own data into a "subkey" inside the state object instead of erasing the whole state. We will discuss that with Thierry in our next meeting 😉

cc @thierrymichel

@johnrobertcobbold johnrobertcobbold changed the title Add random data to history / pushState Add data to history / pushState Sep 5, 2021
@psntr
Copy link

psntr commented Nov 29, 2021

That would be lovely to have a way to store data in the history state. It could in the same time solve issues with the back and forward button from the browser related to issue #601 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants