Browser history is hard. Even github can't get it right (I found a bug writing this: Click "Raw" and then go Back in Chrome).
##Scenario
AB test single-page-checkout vs. 3 step checkout with minimal code duplication for fewer bugs and chances to pollute the test. 3-step checkout is already in place and refactored using a combination of emerson views and traits.
<div data-view='checkout' data-checkout-path='checkout/customer'>
...
</div>
<div data-view='checkout' data-checkout-path='checkout/shipping'>
<form data-remote='true'>
...
<div data-traits='address-autocompleter'>
<input data-outlet='zipCode'/>
<input data-outlet='city'/>
<input data-outlet='state'/>
<input data-outlet='country'/>
</div>
...
</form>
...
</div>
<div data-view='checkout' data-checkout-path='checkout/billing'>
<form data-traits='stripe-form' data-remote='true'>
<input data-outlet='cardNumber'/>
<input data-outlet='cardCvv'/>
...
<button type='submit'>Apply</button>
</form>
...
</div>
<div data-view='checkout' data-checkout-path='checkout/confirm'>
<div data-view='coupon'>
<div data-sink='coupon-error'></div>
<form data-remote='true' ...>
<input type='text' data-outlet='couponName'/>
<button type='submit'>Apply</button>
</form>
<form data-remote='true' ...>
<button type='submit'>Complete Order</button>
</form>
</div>
...
</div>
var view = define('checkout', {
initialize : function() {
this.pushState();
},
subscribe : function() {
}
});
view.extend({
pushState: function() {
if (history && history.pushState) {
if (!history.state) {
history.replaceState({checkout: true}, "", this.data('checkout-path'));
} else {
history.pushState({checkout: true}, "", this.data('checkout-path'));
}
}
}
});
It also doesn't take into account navigating directly to the URL (yet) as it should behave as expected in the single-page version.
This doesn't even work in all scenarios, take a peak at the For the Makers store.js and the store in action with filtering, pagination, and AFAIK working back button and copy/paste of URL.