As shown in the screenshot, I need the to stay in the question list tab when I submit the form. For the current situation, everytime I refresh or submit the form, it will redirect to the first tab. The current webpage is code in spring boot, thymeleaf, and bootstrap. May I know how to solve it? I will appreciate your guys' helps so much. Thank you!
Below is my nav tab code
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link active" id="home-tab" data-toggle="tab"
data-target="#new-question" type="button" role="tab"
aria-controls="home" aria-selected="true">Add New Question
</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="profile-tab" data-toggle="tab"
data-target="#categorize" type="button" role="tab"
aria-controls="profile" aria-selected="false">Categorize
</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="contact-tab" data-toggle="tab"
data-target="#question-list" type="button" role="tab"
aria-controls="contact" aria-selected="false">Question List
</button>
</li>
</ul>
Below is my attempt to use the localstorage
$(document).ready(function(){
$('a[data-toggle="tab"]').on('show.bs.tab', function(e) {
localStorage.setItem('activeTab', $(e.target).attr('href'));
});
var activeTab = localStorage.getItem('activeTab');
if(activeTab){
$('#myTab a[href="' + activeTab + '"]').tab('show');
}
});