rasool
October 16, 2015, 10:28am
1
My problem is that when i navigate from home state to user.tab1 state, the back button does not appear in navbar, how can i solve this problem, i’m new to ionic
I have this states in my project:
var app = angular.module('myApp', ['ionic']);
app
.config(function ($stateProvider, $urlRouterProvider) {
$stateProvider
.state('home', {
url: '/home',
templateUrl: './templates/test/home.html'
})
.state('user', {
url: '/user',
templateUrl: './templates/test/user.html'
})
.state('user.tab1', {
url: '/tab1',
views: {
'tab1': {
templateUrl: './templates/test/tab1.html'
}
}
})
.state('user.subtab1', {
url: '/subtab1',
views: {
'tab1': {
templateUrl: './templates/test/sub-tab1.html'
}
}
})
.state('user.tab2', {
url: '/tab2',
views: {
'tab2': {
templateUrl: './templates/test/tab2.html'
}
}
});
$urlRouterProvider.otherwise("/home");
});
and these are the templates:
index.html
<body ng-app="myApp">
<ion-nav-bar class="bar bar-calm">
<ion-nav-back-button>
</ion-nav-back-button>
</ion-nav-bar>
<ion-nav-view>
</ion-nav-view>
</body>
home.html
<ion-view view-title="Home">
<ion-content>
<a ui-sref="user.tab1">user.tab1</a>
</ion-content>
</ion-view>
user.html
<ion-view view-title="User">
<ion-tabs>
<ion-tab title="tab1" href="#/user/tab1">
<ion-nav-view name="tab1"></ion-nav-view>
</ion-tab>
<ion-tab title="tab2" href="#/user/tab2">
<ion-nav-view name="tab2"></ion-nav-view>
</ion-tab>
</ion-tabs>
</ion-view>
tab1.html
<ion-view view-title="tab1">
<ion-content>
tab1
<br />
<a ui-sref="user.subtab1">user.subtab1</a>
</ion-content>
</ion-view>
tab2.html
<ion-view view-title="tab2">
<ion-content>
tab2
</ion-content>
</ion-view>
sub-tab1.html
<ion-view view-title="sub-tab1">
<ion-content>
sub-tab1
</ion-content>
</ion-view>
if you create a single holding state for example ‘app’ and have all other states as children of this holding stae, then back button should appear.
.config(function ($stateProvider, $urlRouterProvider) {
$stateProvider
.state('app', {
url: '/app',
abstract: true
templateUrl: './templates/test/main-app-template.html'
})
.state('app.home', {
url: '/home',
templateUrl: './templates/test/home.html'
})
.state('app.user', {
url: '/user',
templateUrl: './templates/test/user.html'
})
.state('app.user.tab1', {
url: '/tab1',
views: {
'tab1': {
templateUrl: './templates/test/tab1.html'
}
}
})
.state('app.user.subtab1', {
url: '/subtab1',
views: {
'tab1': {
templateUrl: './templates/test/sub-tab1.html'
}
}
})
.state('app.user.tab2', {
url: '/tab2',
views: {
'tab2': {
templateUrl: './templates/test/tab2.html'
}
}
});
1 Like
rasool
October 23, 2015, 9:36am
3
Thank you @yurinondualm , and what should be the content of main-app-template.html ?
Something like that:
<ion-view hide-back-button="false">
<ion-side-menus>
<ion-side-menu side="left">
<ion-nav-view name="side-menu-view"></ion-nav-view>
</ion-side-menu>
<ion-side-menu-content drag-content="false">
<ion-nav-bar align-title="center">
<ion-nav-buttons side="left">
<button menu-toggle="left" class="button button-icon icon ion-navicon">
</button>
</ion-nav-buttons>
<ion-nav-back-button class="button-clear button-icon">
<!-- <i class="icon ion-ios7-arrow-back"></i> Back -->
<!-- <i class="ion-arrow-left-c"></i> Back -->
Back
</ion-nav-back-button>
</ion-nav-bar>
<ion-nav-view name="main-view">
</ion-nav-view>
</ion-side-menu-content>
</ion-side-menus>
</ion-view>
This is my app’s config (sorry for coffeescript)
$stateProvider
.state "App",
url: "/app"
abstract: true
controller: "appController"
templateUrl: "templates/app-main-template.html"
.state "App.Tabs",
abstract: true
url: "/tabs"
cache: false
views:
"main-view":
templateUrl: "templates/tabs.html"
controller: "tabsController"
"side-menu-view":
templateUrl: "templates/side-menu.html"
controller: "sideMenuController"
And then for example if you want view without tabs you can do:
.state "App.Walkthrough",
url: "/walkthrough"
views:
"main-view":
templateUrl: "templates/walkthrough.html"
controller: "walkthroughController"
And view with Tabs:
.state "App.Tabs.Login",
url: "/login"
views:
"auth-tab-view":
templateUrl: "templates/login.html"
controller: "loginController"
rasool
October 23, 2015, 9:47am
6
I changed states as you said, and create main-app-template with this content:
<ion-view hide-back-button="false">
<ion-nav-bar class="bar bar-calm">
<ion-nav-back-button>
</ion-nav-back-button>
</ion-nav-bar>
<ion-nav-view>
</ion-nav-view>
</ion-view>
and this is index.html
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<link rel="stylesheet" href="lib/ionic/css/ionic.css" />
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="cordova.js"></script>
<script src="js/app.js"></script>
</head>
<body ng-app="app">
<ion-nav-bar class="bar bar-calm">
<ion-nav-back-button>
</ion-nav-back-button>
</ion-nav-bar>
<ion-nav-view>
</ion-nav-view>
</body>
</html>
but currently, back-button doesn’t appear when navigate from home state to user state!!!
rasool:
<ion-nav-view>
Sorry but you have to figure this yourself. Try giving name to your <ion-nav-view>
inside of main-app-template and remove back button from index.html
my index.html is like this:
<body id="mainApp" ng-app="mainApp">
<ion-nav-view></ion-nav-view>
</body>
rasool
October 23, 2015, 10:30am
8
Dear @yurinondual , this is www folder of my project, could you change the states and templates to working correctly, please?
https://goo.gl/KG3fXC
th app preview:
https://goo.gl/PPchYL
it’s very critical and i couldn’t solve it.
A back button will not show when navigating from a non tabbed state to a tabbed state, there are some issues for this here:
In addition to this, any page outside of the tabs navigation structure has issues with displaying the back button, presumably for reasons related to the lack of animation.
For example, my app has a dashboard as the first screen with no tabs. From the dashboard you can tap an icon to go to any tabbed page. For this example, say I tapped ‘News’. News has a list of articles which you can tap to see the full article. When I navigate to a full article the back button is not visible until I navigate …
So this is because you are going from a tabbed view, to a non-tabbed view.
So because tabs can maintain multiple navigations stacks all at once, they tend not to play well with view that are not tabbed views.
So what you are seeing is a case where ui-router and our history manager can’t keep track all a multi-stack history view, and a linear history view.
Hi, after rereading this closed issue I think this is not a problem but the expected behaviour. The back button is displayed if the the user goes from Tab A->Parent view to Tab A->Child view (same tab). If the user goes from Tab A to Tab B->Child view, the back button must not display.
The reported problem in that issue (the user goes from Tab A to Tab B->Child view and can’t navigate up to Tab B->Parent view) is working fine at least in the latest version.
There’s a large github issue on this here:
opened 07:37PM - 27 Jan 15 UTC
closed 04:30AM - 27 Apr 16 UTC
**Type**: <span ionic-type>bug</span>
**Platform**: <span ionic-platform>all</s… pan>
<span ionic-description>Codepen http://codepen.io/mhartington/pen/zxdGKd
If you navigate to and from tabs, there are no view transitions.
Also, the back button will not show either.</span>
<span is-issue-template></span>
Unfortunately, we will not be fixing it in 1.0 because of the limitations of ui-router. Fortunately, Ionic version 2.0 supports this and it is currently in Alpha: Announcing Ionic 2.0 Alpha - Ionic Blog
rasool
October 24, 2015, 1:51pm
10
@brandyshea , Thank you, i installed ionic2@alpha and created a simple app that have only to page, home page and tabs page, and when navigate from home to tabs, back-button of navigation doesn’t appear again!!!
but you said that this problem is solved in ionic2@alpha!!!
rasool
October 26, 2015, 3:20pm
12
Thanks for your effort, but if you change $urlRouterProvider.otherwise("/app/tabs/tab1");
to $urlRouterProvider.otherwise("/app/home");
, it doesn’t work properly.
If you change the code, when the page loaded completely, the back button appears in nav-bar, and when navigate from home to tabs, the back button doesn’t appears!!
1 Like
Sorry but you will have to do this yourself, just use my code as an example
2 Likes
rasool
October 26, 2015, 3:35pm
14
I know, but as you seen, @brandyshea said that it is bug of ionic and doesn’t resolved yet. i’m mean this should be handled by ionic and is a simple problem. thank you dear @yurinondual
You can create your own back button like I did in the example above and use ionicHistory to go back
1 Like