samedi 18 février 2017

Prevent pushState on initial page load and when clicking Back when using Bootstrap tab 'shown' event

On Bootstrap's 'shown.bs.tab' event, there is a pushState:

  $('a[data-toggle="tab"]').on('shown.bs.tab', (e) => {
    let targetHref = $(e.target).attr('href');
    // do stuff to dynamically generate tab's content
    changeState('view', targetHref.slice(1)); // history.pushState('', '', 'http://ift.tt/2lwFJ88')
  });

When loading the page, or when pressing the Back button, the Tab is programmatically refreshed:

function refreshPageBasedOnURL() {
  queries = parseQuery(location.search.substr(1)); // {'view': 'bar'}
  let defaultView = queries['view'] || 'map';
  $("#idNavTabs").find(`a[href="#${defaultView}"]`).tab('show');
}

How can I prevent changeState from running on the initial page load and on clicking the back button?

Aucun commentaire:

Enregistrer un commentaire