millermedeiros / crossroads.js

JavaScript Routes
http://millermedeiros.github.com/crossroads.js/
1.44k stars 156 forks source link

using crossroads routes with bootstrap tabs #137

Open liammcsheffrey opened 9 years ago

liammcsheffrey commented 9 years ago

Hi, I'm trying to set up crossroads.js to work with bootstrap tabs, so a URL may be /mainpage#latestnews

Looking at hasher and history.js, is there an example as to how this can work and how hash tab routes can be created?

Thanks

rain-sk commented 7 years ago

(with jQuery) I use

$(window).on('hashchange', function(e){ // code to switch bootstrap tabs });

Based on the answer from the following SO question...

https://stackoverflow.com/questions/17830590/bootstrap-tab-activation-with-jquery

your implementation could look something like:


// detect hashchange
$(window).on('hashchange', function(e){

  // clean #hash
  var hash = window.location.hash.substr(1);

  // "show" the tab with #{hash} url
  $('.nav-tabs a[href="#' + hash + '"]').tab('show');

});