Reputation: 111
Is there a way in Ionic framework to have a nested tab bar like this:
I tried it in Codepen, but it doesn't really work:
.state('tabs.about', {
url: "/about",
abstract: true,
views: {
'about-tab': {
templateUrl: "templates/about.html"
}
}
})
.state('tabs.about.page1', {
url: "/page1",
views: {
'about-page1': {
templateUrl: "templates/about-page1.html"
}
}
})
.state('tabs.about.page2', {
url: "/page2",
views: {
'about-page2': {
templateUrl: "templates/about-page2.html"
}
}
});
Is there someone who knows the proper way to do this?
Thanks
Upvotes: 8
Views: 6122
Reputation: 540
I try to example at codePen but I doesn't work as I expected. But I solved your problem in a local project. Be sure you have the last version of ionic or you can update it with:
npm install -g ionic
You are almost there. You need to set a abstract into the views like this:
angular.module('ionicApp', ['ionic'])
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('tabs', {
url: "/tab",
abstract: true,
templateUrl: "templates/tabs.html"
})
.state('tabs.home', {
url: "/home",
views: {
'home-tab': {
templateUrl: "templates/home.html",
}
}
})
.state('tabs.about', {
url: "/about",
views: {
'about-tab': {
templateUrl: "templates/about.html",
abstract: true
}
}
})
.state('tabs.about.page1', {
url: "/page1",
views: {
'about-page1': {
templateUrl: "templates/about-page1.html"
}
}
})
.state('tabs.about.page2', {
url: "/page2",
views: {
'about-page2': {
templateUrl: "templates/about-page2.html"
}
}
});
$urlRouterProvider.otherwise("/tab/home");
});
And using the code that you had commented:
<ion-tabs class="tabs-striped tabs-top tabs-background-stable">
<ion-tab title="Page 1" ui-sref="tabs.about.page1">
<ion-nav-view name="about-page1"></ion-nav-view>
</ion-tab>
<ion-tab title="Page 2" ui-sref="tabs.about.page2">
<ion-nav-view name="about-page2"></ion-nav-view>
</ion-tab>
</ion-tabs>
I comment the previous tab code, specifically this:
<!--<div class="tabs-striped tabs-top tabs-background-stable">
<div class="tabs">
<a class="tab-item" ui-sref="tabs.about.page1">
Page 1
</a>
<a class="tab-item" ui-sref="tabs.about.page2">
Page 2
</a>
</div>
</div>-->
The rest of the HTML code is the same
My ionic version is: 1.3.19
I hope it helps you
Upvotes: 6