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

Allow links to replace history state instead of pushing a new state #460

Closed
Mamboleoo opened this issue Oct 24, 2019 · 8 comments
Closed

Comments

@Mamboleoo
Copy link

Hi,
I wanted to know if it would be an interesting feature to allow some links to replace the current browser history state instead of pushing it.
For example, when you're on a product page on Amazon you can switch from one colour to another one without pushing new entries in your browser history.

I'm currently working on a project with a similar situation like the Amazon one and it would be nicer for our users to not have to press the Back button multiple time when they want to get back to the 'previous page'.

I think it could work either with a data-attribute like (data-barba-history="replace") or with an option on the init phase similar to the prevent function.

What do you think of such feature?

@luruke
Copy link
Member

luruke commented Oct 24, 2019

@Mamboleoo, yeah, that's indeed a good case scenario and I think it's something we can add

@xavierfoucrier
Copy link
Member

@Mamboleoo I love this idea! +1 for that 😉

@luruke
Copy link
Member

luruke commented Oct 24, 2019

@Mamboleoo perhaps you want to work on a PR? 🤓

@thierrymichel
Copy link
Member

@Mamboleoo could you try with @next release (https://www.npmjs.com/package/@barba/core/v/2.9.0) ?
Thanks in advance!

@Mamboleoo
Copy link
Author

Mamboleoo commented Nov 26, 2019

@thierrymichel Thanks for the update 🙀 If I get it right from the commit, I need to add a data-barba-history attribute with either push or replace? (Push being the default so unnecessary to write)

@thierrymichel
Copy link
Member

@Mamboleoo absolutely! :)
If it works as expected, I will add an option where you can put some logic…

@Mamboleoo
Copy link
Author

I just implemented the new version on my current project and it's working like a charm! 💖
Thanks again for this feature, I think it could help others :)

@lionettiluca
Copy link

Hi guys,
I'm sorry for comment in a closed issue, but how can we use this implementation with API?
I've seen the add method code but I can't understand if is possible to replace history with something like barba.history.add('?query=search', 'replace')
Thanks in advance 🙏

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

5 participants