看着幾個方案的組合之後(從這裏幫助: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();
});