I'm using Bootstrap pills in my app:
<div class="container">
<ul class="nav nav-pills">
<li class="active"><a data-target="#home" data-toggle="tab">Home</a></li>
<li><a href="#about" data-toggle="tab">About</a></li>
<li><a href="#contacts" data-toggle="tab">Contacts</a></li>
</ul>
</div>
<div class="tab-content">
<div class="tab-pane active" id="home">Home</div>
<div class="tab-pane" id="about">About</div>
<div class="tab-pane" id="contacts">Contacts</div>
</div>
In order to stay on the same tab after page reload I use the following function:
$(function() {
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
localStorage.setItem('lastTab', $(this).attr('href'));
});
var lastTab = localStorage.getItem('lastTab');
if (lastTab) {
$('[href="' + lastTab + '"]').tab('show');
}
});
The problem is that after page reload, the first tab becomes active for 1 second and then it jumps to the actual active tab. Can I keep current tab without this 'jumping'?