Ionic2 - nav.setRoot(Component) - Works only first time, unable to navigate after, no errors reported
Short description of the problem:
I am developing an app with Ionic2. I have App.ts as the parent, Welcome.ts as a child page and Featured.ts as a child page as well. I have firebase integrated with the app. Rootpage is first set to Welcome.
this.rootPage = Welcome;
Step 1: I click a button on Welcome to authenicate with Google, once onAuth is called, I set this.nav.setRoot(Featured); All works fine up to now. I get to the Featured page which enables a sidemenu with different pages and i am able to navigate to all of them no problem.
Step 2: Featured enables a sidemenu from App.ts/html, in there I have a logout button that calls unauth. Unauth does some Firebase unauth and then:
this.menu.close();
let nav = this.app.getComponent('nav');
nav.setRoot(Welcome);
Step 3: Login again same as in step 1. All is fine up to now.
Step 4: Open side menu, selects any of the pages from the sidemenu, navigation doesn't occur. sidemenu closes but page remain the same, navbar icon button disappear and no navigation occurs. openPage code:
openPage(page) {
//1. Loop through and set active attribute to False if it doesn't match.
// Set to True if it matches page title
for(var i = 0; i < this.NavPages.length; i++) {
if(this.NavPages[i].title == page.title) this.NavPages[i].active = true;
else this.NavPages[i].active = false;
}
for(var i = 0; i < this.ActivityPages.length; i++) {
if(this.ActivityPages[i].title == page.title) this.ActivityPages[i].active = true;
else this.ActivityPages[i].active = false;
}
for(var i = 0; i < this.PreferencesPages.length; i++) {
if(this.PreferencesPages[i].title == page.title) this.PreferencesPages[i].active = true;
else this.PreferencesPages[i].active = false;
}
//2. close the menu when clicking a link from the menu
this.menu.close();
//3. navigate to the new page if it is not the current page
let nav = this.app.getComponent('nav');
nav.setRoot(page.component);
}
What behavior are you expecting?
I am expecting navigation to continue to occur, similar to what happens in step 1.
Steps to reproduce: Steps to reproduce included above.
Code included above.
Other information: (e.g. stacktraces, related issues, suggestions how to fix, stackoverflow links, forum links, etc) No error is being thrown unfortunately. I don't see any erros in the console logs.
Which Ionic Version? 2.x
Run ionic info from terminal/cmd prompt: (paste output below)
Your system information:
Cordova CLI: 6.0.0
Gulp version: CLI version 3.9.0
Gulp local: Local version 3.9.1
Ionic Version: 2.0.0-beta.3
Ionic CLI Version: 2.0.0-beta.19
Ionic App Lib Version: 2.0.0-beta.9
ios-deploy version: 1.8.2
ios-sim version: 5.0.3
OS: Mac OS X El Capitan
Node Version: v0.12.7
Xcode version: Xcode 7.2.1 Build version 7C1002
Thank you.
I noticed the following: 2 ion pages are present at once in the dom.

The one I navigated to is "explore" which has a lower z-index(92) than the "featured" page. Therefore I should be on explore but the "featured" is overlayed on top of "explore" with a z-index of 93.
I'm experiencing the same issue but in my case I can't even get redirected after login.
If I'm already logged and land in the login view, nav.setRoot(TabsPage) is executed perfectly.
But if I log-in with facebook after getting the user probile nav.setRoot(TabsPage) is doing nothing. Moreover, nav.push(TabsPage) is also doing nothing, but if I do nav.push(Main) where Main is one of my tabs, is executing correctly, but I don't have tabbar and a back button appears, obviously.
Also if I do nav.setRoot(Main) it works correctly, but I land in a tab without tabbar and with back button.
I add some information. I saw in the docs that setRoot return a promise, so I did this:
this.nav.setRoot(TabsPage)
.then(data => {
console.log(data);
}, (error) => {
console.log(error);
})
This throws true when I land on the login page and I'm already logged, but throws nothing when I login with facebook, so it seems that the promise is never resolved.
Ok, another update. If you go to the core of Ionic2 to components/nav/nav-controller.js in the function setPages which is called from setRoot the callback of the transition is never been executed. If you follow the flow of functions called: setRoot -> setPages -> _transition -> _render -> _postRender
In the _render function:
this.loadPage(enteringView, null, opts, function () {
if (enteringView.onReady) {
// this entering view needs to wait for it to be ready
// this is used by Tabs to wait for the first page of
// the first selected tab to be loaded
enteringView.onReady(function () {
enteringView.loaded();
_this._postRender(transId, enteringView, leavingView, isAlreadyTransitioning, opts, done);
});
}
else {
enteringView.loaded();
_this._postRender(transId, enteringView, leavingView, isAlreadyTransitioning, opts, done);
}
});
My code enters in enteringView.onReady and the callback is never executed.
If I just call the _postRender method before waiting for enteringView.onReady my app works fine, but It's so dirty.
The problem seems to be waiting for the page of the tab to be ready. I think it never gets ready or never acquire fine the ready state.
Could be this something with my code? Or is likely to be a bug?
Thank you!
I have the same problem with Google or Facebook auth
@privetr this seems to have been fixed with beta4. Can you please check ? Mine is working fine now.
@jorchg Can you check as well ? when you get a chance :)
Hello all! As it looks like this was fixed in beta.4 i will be closing this issue, but if you are still having this issue feel free to comment!
I am still having this issue. I can't get the nav to push or setRoot to my TabsPage after a Facebook login promise.
Cordova CLI: 6.1.1
Gulp version: CLI version 1.2.1
Gulp local: Local version 3.9.1
Ionic Framework Version: 2.0.0-beta.4
Ionic CLI Version: 2.0.0-beta.24
Ionic App Lib Version: 2.0.0-beta.14
ios-deploy version: 1.8.5
ios-sim version: 5.0.8
OS: Mac OS X El Capitan
Node Version: v5.9.1
Xcode version: Xcode 7.3 Build version 7D175
I also am experiencing the situation where if I call nav.setRoot(x), the new page doesn't actually appear. Yet, if I focus an input field in the current page, it disappears and shows the correct page.
Additionally, if I push onto the stack instead of setRoot, the animation doesn't happen until I focus an input field.
Same problem.
Edit: Just swapped out the navigation in my app to a sidemenu and everything is working fine. So the tabs are borked as of beta 4 FYI.
@daveshirman are you using tabs to navigate around ? It might be related to tabs, my issue was related to sidemenu. However they both use the navcontroller, not sure why it would work for me and not for you.. Maybe produce a plunker or open a new issue and the ionic team will be able to help out.
I was having the same issue : nav.setRoot(MyComponent) did not seem to do anything. I was running the app in Android using --live-reload, and there were warnings about some events not being fired :
0 195445 log deviceready has not fired after 5 seconds.
1 195457 log Channel not fired: onDOMContentLoaded
I also could not test the code in the browser because it's about displaying a certain page when the device goes offline.
So I finally tried to run my code in Android, but without the live reload, and it works fine.
So, there is something about the live reload mode that is preventing it from working. Using Beta4 as my dependency, and the CLI version 2.0.0-beta25.
I have the issue like this: Tabs persist after logging out of app, start stacking on log in
I'm still experiencing the issue I described. I completely forgot, and after a ionic update it stopped working, so I just modified it again as described in my latest post in this thread.
Should I open another issue?
Hi Everyone. Did anyone find a fix for this? I am currently using Ionic [email protected] and the problem is still present!
I found the cause for my issue was calling .pop() when only setRoot had been called.
I found that calling it from my app.ts seems to work reliably. Calling it from any other page seems to fail. Additionally, if I am not on a root page, like 3 pages deep, I also call nav.popToRoot() after the setRoot method, which works:
this.nav.setRoot(xxxx).then(() =>{
this.nav.popToRoot();
//....
});
Why is this issue closed? Navigation seems really broken. If i push a page with forms in it it wont work either.
Also breaks when there's a modal window showing too. On 13 Jul 2016 3:59 a.m., "scorpnode" [email protected] wrote:
Why is this issue closed? Navigation seems really broken. If i push a page with forms in it it wont work either.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/driftyco/ionic/issues/5883#issuecomment-232241198, or mute the thread https://github.com/notifications/unsubscribe/ANnlXmqTT5pf0i-JZNog5F32j8pB785Qks5qVFSZgaJpZM4H0Jz0 .
Hi, this is still occurring to me in 2.0.0-beta.10. I'm getting a blank screen after calling NavController.setRoot. Only occurring on iOS devices
device info:
- model: iPad5,4
- iOS version: 8.3