在查看了几种解决方案的组合(从这里获得帮助:http: //bit.ly/1qIemCh )并将其浓缩为一个可行的解决方案之后,这对我来说是允许AngularJS
+的解决方案。Bootstrap Tabs
诀窍是利用HTML5 pushstate
JS 从历史记录中获取 URL 哈希,找到适用的选项卡并显示它。
标签:
<ul class="nav nav-tabs" role="tablist" id="myTab">
<li class="active"><a href="#" data-target="#">Home</a></li>
<li><a href="#/tab2" data-target="#">Tab 2</a></li>
<li><a href="#/tab3" data-target="#">Tab 3</a></li>
</ul>
这JS
将从历史记录中激活正确的选项卡,或者如果也通过书签进行导航:
function setActiveTab() {
var hash = window.location.hash;
var activeTab = $('.nav-tabs a[href="' + hash + '"]');
if (activeTab.length) {
activeTab.tab('show');
} else {
$('.nav-tabs a:first').tab('show');
}
};
//If a bookmark was used to a particular page, make sure to
//activate the correct tab after initial load:
$(document).ready(function() {
setActiveTab();
});
//When history.pushState() activates the popstate event, switch to the currently
//selected tab aligning with the page being navigated to from history.
$(window).on('popstate', function () {
setActiveTab();
});