Barba: Allow links to replace history state instead of pushing a new state

Created on 24 Oct 2019  Â·  7Comments  Â·  Source: barbajs/barba

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?

@barbcore discussion feature

Most helpful comment

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

All 7 comments

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

@Mamboleoo I love this idea! +1 for that :wink:

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

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

@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)

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

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 :)

Was this page helpful?
0 / 5 - 0 ratings