I have set up my template pages and my routes. My page transition does not work when I change state to 'login' state, it just shows the page without transition. I don't know what the problem could be. My application's main page is index.html with an <ion-nav-view> element.
Here is my routing code:
config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('app', {
url: "/app",
abstract: true,
templateUrl: "templates/menu.html",
controller: 'AppCtrl'
})
.state('app.home', {
url: '/home',
views: {
'menuContent': {
templateUrl: "templates/home.html",
controller: 'HomeCtrl'
}
}
})
.state('login', {
url: "/login",
templateUrl: "templates/login.html",
controller: 'LoginCtrl'
});
$urlRouterProvider.otherwise('/app/home');
})
menu.html: This page is the parent state. Other pages inherit from it.
<ion-pane ion-side-menu-content>
<ion-nav-bar class="bar-stable" id="header" animation="slide-left-right">
<ion-nav-back-button class="button-clear"><i class="icon ion-ios7-arrow-back"></i> Back</ion-nav-back-button>
<img src="img/logo.png" alt="EasySpree" />
<ion-nav-buttons side="right">
<button class="button button-icon icon ion-ios7-email">
</button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-nav-view name="menuContent"></ion-nav-view>
</ion-pane>
index.html: Main Page - route defined on this page
<ion-nav-view id="main" animation="slide-left-right-ios7"></ion-nav-view>
You have to put it in the animation="slide-left-right" in of your menu.html page.
E.g. menu.html:
<ion-pane ion-side-menu-content>
<ion-nav-bar class="bar-stable" id="header" animation="slide-left-right">
<ion-nav-back-button class="button-clear"><i class="icon ion-ios7-arrow-back"></i> Back</ion-nav-back-button>
<img src="img/logo.png" alt="EasySpree" />
<ion-nav-buttons side="right">
<button class="button button-icon icon ion-ios7-email">
</button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-nav-view name="menuContent" animation="slide-left-right"></ion-nav-view>
I have created a tool Ionic builder to build barebones for ionic app. This will build all needed pages and files, add transitions, tabs or side menus. You can generate the app and download the code. Please give it a try!
In my case, I was routing to another module -
So I was going from
/tabs/plan
to
/tabs/dinners/edit/123
Once I added the edit component to the routing of my plan module, the transitions worked. I did not need to duplicate the component itself - it is still in the dinner module.
E.g.:
/tabs/plan/edit/123
Related
I am facing an issue with routing. The url changes to the expected one, but the template never loads, and there are no errors on the console. I am using Ionic 1 for my project.
Here is my routing configuration.
$stateProvider
.state('admin', {
url: "/admin",
views: {
'landing': {
templateUrl: "templates/admin/admin-login.html",
controller: 'AdminLoginController'
}
}
})
.state('adminapp', {
url: '/adminapp',
abstract: true,
views: {
'admin': {
templateUrl: "templates/admin/admin-main.html",
controller: 'AdminLoginController'
}
}
})
.state('adminapp.parking', {
url: "/adminparking",
views: {
'adminMenuContent': {
templateUrl: "templates/admin/admin-home.html",
controller: 'AdminHomeController'
}
}
})
And below is the snippet in index.html
<body ng-app="starter" class="starter">
<ion-nav-view name="landing"></ion-nav-view>
<ion-nav-view name="admin"></ion-nav-view>
</body>
And below is the admin-main.html
<ion-side-menus enable-menu-with-back-views="false" ng-init="initAdmin()">
<ion-side-menu-content>
<ion-nav-bar class="bar-stable">
<ion-nav-back-button>
</ion-nav-back-button>
<ion-nav-buttons side="left">
<button class="button button-icon button-clear ion-navicon" menu-toggle="left">
</button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-nav-view name="adminMenuContent"></ion-nav-view>
</ion-side-menu-content>
<ion-side-menu side="left">
<div ng-include="'templates/admin/admin-menu-template.html'"></div>
</ion-side-menu>
</ion-side-menus>
I had to use two views since, the login page doesn't have a menu, and all other pages after login has menu, and as per some ionic forum posts I have to do it with two views.
The initial landing page url is /pg-admin/index.html#/admin. After login it navigates to pg-admin/index.html#/adminapp/adminparking.
When I select 'Logout' option from the Panel menu, I am navigating back to /pg-admin/index.html#/admin. But it never loads the login page, though the url is now changed. I am trying to navigate to login as below
$state.go('admin', {});
Navigation within the 'admin' view is working fine. For example if I navigate to
pg-admin/index.html#/adminapp/settings, this is working.
Anything wrong with the routing configuration? I guess there is something fishy around the abstract view.
I'm struggling with such a simple thing. I have a side menu in ionic. I want the post page to be a child view of the home page. But when I navigate to the post page from the home page, the back button is missing. Also I'm not sure how to define the navbar (index.html, menu.html or post.html).
Router:
$stateProvider
.state('menu', {
url: '/menu',
abstract: true,
templateUrl: 'templates/menu.html'
})
.state('menu.home', {
url: '/home',
views: {
'menuContent': {
templateUrl: 'templates/home.html',
controller: 'HomeCtrl',
resolve: {authResolve: authResolve}
}
}
})
.state("post", {
url: "/home/:uid/:postId",
templateUrl: "templates/timeline/post.html",
controller: "PostCtrl as post",
resolve: {authResolve: authResolve}
})
index.html:
<body ng-app="starter" animation="slide-left-right-ios7">
<div>
<div>
<ion-nav-bar>
<ion-nav-back-button side="left" class="button-icon ion-arrow-left-c"></ion-nav-back-button>
</ion-nav-bar>
<ion-nav-view></ion-nav-view>
</div>
</div>
menu.html:
<ion-side-menus enable-menu-with-back-views="true">
<ion-side-menu-content>
<ion-nav-bar class="bar-positive">
<ion-nav-buttons side="left">
<button class="button button-icon button-clear ion-navicon" menu-toggle="left"></button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-nav-view name="menuContent"></ion-nav-view>
</ion-side-menu-content>
post.html:
<ion-view>
<ion-nav-bar>
<ion-nav-back-button side="left" class="button-icon ion-arrow-left-c"></ion-nav-back-button>
</ion-nav-bar>
the back button need to be only in the higher template (don't repeat it in the post.html). To activate the back button in post.html, the view need to be a child in menu.html template. To do that you post.html route need to be declare like :
.state("menu.post", {
url: "/post/:uid/:postId",
views:
'menuContent' :{
templateUrl: "templates/timeline/post.html",
controller: "PostCtrl as post",
resolve: {authResolve: authResolve}
}
})
See ionic example to understand better what happen.
Try changing .state('post') to .state('menu.post') to make post a sub of the menu.
Likewise, if post is a sub of home, you can chain it like menu.home.post.
I have a following problem with routing in my ionic app:
I have a nested view inside options so I can use inheritance in my routing, but what happens when I get inside the security tab is, that ion-nav-back-button doesn't work at all, although it's shown in my nav bar.
I'm new to ionic, any advise would be appreciated, thanks
app.config
$stateProvider
.state('layout', {
abstract: true,
templateUrl: 'views/menu.html'
})
.state('layout.options', {
views: {
'menuContent': {
templateUrl: 'views/options.html'
}
}
})
.state('layout.options.security', {
views: {
'myView': {
templateUrl: 'views/security.html',
}
}
})
menu.html
<ion-side-menu-content>
<ion-nav-bar class="bar-stable">
<ion-nav-back-button>
</ion-nav-back-button>
<ion-nav-buttons side="left">
...
</ion-nav-buttons>
</ion-nav-bar>
<ion-nav-view name="menuContent"></ion-nav-view>
</ion-side-menu-content>
options.html
<ion-nav-view name="myView">
<ion-view title="Options">
<ion-content>
...
</ion-content>
</ion-view>
</ion-nav-view>
security.html
<ion-view title="Security">
<ion-content>
...
</ion-content>
</ion-view>
I've "solved" my problem by not nesting the security.html inside the options.html
so currently I have
.state('layout.security', {
views: {
'menuContent': {
templateUrl: 'views/security.html',
}
}
})
I feel this is not the right solution, but I got to make it work. Please, if you have solution / reason, why the previous code doesn't work, share
thanks
Basically I am trying to transition from my root.home state to root.topic.section (a topic view with a nested section view). The view loads but my back button and view title do not appear. The view title stays the same as it was in root.home. I don't understand because when i use ui-sref to change to sibling state (with no child states) then it DOES change the title.
EDIT: When I navigate from root.home to a sibling page root.dbtest, dbtest created a new navbar element in the DOM with the correct title, and sets the home's navbar to 'cached'. But when I navigate from root.home to root.topic.section no new DOM element is created and home remains active.
EDIT 2 this is the 'ui-sref' i am using to link to the sub state from root.home.
<a ui-sref="root.topic.section({topicId: xxx, inStore: false, topicName: xxx, sectionType: SECTION_TYPE.Summary})">link</a>
.
$stateProvider
.state('root', {
url: '/root',
abstract: true,
templateUrl: 'templates/menu-static.html',
controller: 'MenuCtrl'
})
.state('root.home', {
url: '/home',
views: {
'menuContent': {
templateUrl: 'templates/home.html',
controller: 'HomeCtrl'
}
}
})
.state('root.topic', {
url: '/topic/:topicId/{inStore}',
abstract: true,
cache: false,
views: {
'menuContent': {
templateUrl: 'templates/topic-view.html',
controller: 'TopicCtrl'
}
},
params: {topicName: null}
})
.state('root.topic.section', {
url: '/section/:sectionType',
views: {
'sectionSpace': {
templateUrl: 'templates/topic-section-view.html',
controller: 'TopicSectionCtrl'
}
}
})
Here is a snippet from my menu-static.html
<ion-side-menu-content>
<ion-nav-bar class="bar-stable">
<ion-nav-back-button>
</ion-nav-back-button>
<ion-nav-buttons side="right">
<button class="button button-icon button-clear ion-navicon" menu-toggle="right">
</button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-nav-view name="menuContent">
</ion-nav-view>
</ion-side-menu-content>
Here is a snippet from home.html
<ion-view view-title="All Topics">
<ion-nav-title>All Topics</ion-nav-title>
<ion-content>
</ion-content>
</ion-view>
Here is a snippet from topic-view.html
<ion-view view-title="NOT SHOWING">
<ion-nav-title>NOT SHOWING</ion-nav-title>
<ion-content>
<ion-nav-view name="sectionSpace">
</ion-nav-view>
</ion-content>
</ion-view>
Also: the Url will currently be /root/topic/... This seems undesirable=> you can have root have the url: '', and this will allow the url to be /topic/
The above did not work well for me so I tried this personally and it did work for the Parent:
Topic-view.html
<ion-view view-title="NOT SHOWING">
<div class="tabs-striped tabs-top tabs-background-balanced tabs-color-light">
<div class="tabs">
<a ng-repeat='section in ["Section1", "Section2", "Section3"]' class="tab-item" ng-click='goTo(section.toLowerCase())'>
{{section}}
</a>
</div>
</div>
<ion-nav-view name='sectionSpace'></ion-nav-view>
</ion-view>
And it did work.
I'm not sure what this {inStore} is about but maybe that's for earlier versions of Ionic/Angular I think I got this working in this codepen: http://codepen.io/zargold/pen/qZNJNJ?editors=1011
In my application with a side menu and several pages. One of those pages, (let's call it Page A) has tabs, everything was working OK - side menu changes the screen with different pages, Page A with tabs had it's tabs working.
Things went south when I tried to add another page with tabs (let's call it Page B). If I am on any page and click on Page A, Page A appears, its tabs works ok. If I click on side menu to open Page B, the URL changes, but nothing happens (Page A is still on screen). All other pages load without problems. If I refresh the browser with Page B URL opened, or refresh on any page other than Page A and then click on Page B side menu link, Page B loads OK, and the reverse happens - any page but Page A will load.
If I comment the code to have tabs on either Page A or Page B, everything works again. So it seems that I can't have an app with side menu and two different pages with different tabs. Is that correct?
Here's my code (relevant parts):
index.html:
<body ng-app="kinofit">
<ion-nav-view></ion-nav-view>
</body>
app.js:
angular.module('kinofit', ['ionic'])
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('app', {
url: "/app",
abstract: true,
templateUrl: "templates/menu.html",
controller: 'AppCtrl'
})
.state('app.home', {
url: "/home",
views: {
'menuContent': {
templateUrl: "templates/home.html",
controller: 'HomeCtrl'
}
}
})
.state('app.aerobico', {
url: "/aerobico",
views: {
'menuContent': {
templateUrl: "templates/aerobico.html",
controller: 'AerobicoCtrl'
}
}
})
.state('app.musculacao', {
url: "/musculacao",
views: {
'menuContent': {
templateUrl: "templates/musculacao.html",
controller: 'MusculacaoCtrl'
}
}
});
templates/menu.html:
<ion-side-menus enable-menu-with-back-views="false">
<ion-side-menu-content>
<ion-nav-bar class="bar-balanced">
<ion-nav-back-button>
</ion-nav-back-button>
<ion-nav-buttons side="left">
<button class="button button-icon button-clear ion-navicon" menu-toggle="left">
</button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-nav-view name="menuContent"></ion-nav-view>
</ion-side-menu-content>
<ion-side-menu side="left">
<ion-content>
<ion-list>
<ion-item nav-clear menu-close href="#/app/home">
<i class="icon ion-home"></i> Início
</ion-item>
<ion-item nav-clear menu-close href="#/app/aerobico">
<i class="icon ion-heart"></i> Aeróbico
</ion-item>
<ion-item nav-clear menu-close href="#/app/musculacao">
<i class="icon ion-checkmark-circled"></i> Musculação
</ion-item>
</ion-list>
</ion-content>
</ion-side-menu>
</ion-side-menus>
templates/musculacao.html:
<ion-view view-title="MUSCULAÇÃO" class="musculacao-view">
<ion-tabs tabs-type="tabs-icon-top" class="tabs-striped">
<ion-tab title="Tab 1">
<ion-content class="tabbed-content-within-sidemenu-app padding">
(...)
</ion-content>
</ion-tab>
<ion-tab title="Tab 2">
<ion-content class="tabbed-content-within-sidemenu-app padding">
(...)
</ion-content>
</ion-tab>
</ion-tabs>
</ion-view>
and templates/aerobico.html is the same, changing the view-title and class attributes.
I'm aware that codepen or similar websites would be better to post the code, but I couldn't make it work with multiple html files.
Any help would be greatly appreciated. Thanks.
Seems like problem related to caching of views, views Caching is by default enable in ionic framework
You need to Disable all caching by setting it to 0, before using it add $ionicConfigProvider dependency.(Do add it in config block)
$ionicConfigProvider.views.maxCache(0);
Similar answer here
OP Edit: I couldn't get this to work, but adding cache:false to the $stateProvider call (solution #2 on the "answer here" link above) did the trick for me (OP).