I’m still using getRootNav(), I don’t want to use already now a workaround
It still gives a message in the console
So I used getActiveNavs instead, and it worked
Thanks!
I figured out how to use .getRootById() and then set root.
this.app.getRootNavById(‘n4’).setRoot(SomePage); //does not work
BUT
testNav; //declared earlier on in program
this.testNav = this.app.getRootNavById(‘n4’);
this.testNav.setRoot(LoginPage); //WORKS! no console warning
WHY ‘n4’?
console.log(this.app.getRootNav()); // it will show you the ids. they don’t seem to change
Why n4
is the question which is still not solved in the GitHub issue of Ionic:
In addition to my earlier comment suggesting that attempting to reach navigation stacks outside of one’s own domain is indicative of bad app design, we should not be asking “why ‘n4’?”. If something is undocumented, that means it is an internal framework implementation detail. App code must not rely on any aspect of internal framework implementation details. It becomes brittle and unmaintanable.
sorry but yes and no. I understand your point but then if it’s the case why displaying a msg telling that a method is deprecated and advising users to use another where you have to pass an/that id?
furthermore seems that even internal to the ionic team not everybody knows what is n4
I’m clearly not qualified to speak for the Ionic team, and they have many recommendations that I strongly disagree with. Suggesting people grab navigation controllers across component boundaries by any means is one of them.
no worries, you know I just like when stuffs are clear, like if a framework method is deprecated just telling what exactly should be use in the framework instead, to be sure that in the the future it is still gonna work
I understand your concern about the grabing the navigation
Well let see if one day the question gonna be answered or if the msg/recommandation gonna be modified or if the deprecated method gonna disappear before
Can you suggest an alternate storyboard/structure
For an app that goes from a page to Tabbed page then to another page that is outside of the tabbed pages?
Like this:
LoginPage => Menu-Tabs(MainPage using .getRootNavById to get to) => OtherPage
I would think about using a modal here. See this discussion for more context.
If you find any solution to this, please let us know.
@rapropos Just to be sure, @setRoot is not deprecated yet? Ty
There should be the way to use navigation inside services. There are many standard cases, where developer need this functional and this is not “broken design”. For example, many apps need to verify session token, and if it expired - redirect to sign in
page. This is absolutely normal dynamic logic and developer can not be 100% sure on what page this happen.
Such dirty hacks as
private get _navCtrl(): NavController {
return this._app.getRootNav();
}
is deprecated and will be removed in future major version. But no alternative has yet been proposed and it’s very sad.
Thx for your comment, but this has nothing to do with the subject of this post
But about your question, there is a way to achieve what you are looking for by using Observable & Subject
for example
I have no question. My apps works fine, for now. I’m care about future support. This topic about getRootNav() deprecated
, so if some one from ionic team see my answer - it will be helpful.
Using Observable & Subject
is not scalable solution.
I guess we won’t be agree…anyway this topic is about using getRootNavById()
instead of getRootNav()
, feel free to open another post about the design, I gonna follow it of course
Is getRootNav() going to stay in or is it depricated.?
will the id remain ‘n4’?
I’ve got absolutely no idea
Thanks, this is a working solution
I do not understand how to actually replace the method getRootNav()
with getRootNavById()
? Which ID? There should be only one root, or not? I want THE root. To push a page on top without having tabs. this.app.getRootNav().push(AnotherPage)
works great. (app
comes from ionic-angular).
What is the root-object which getRootNav()
currently returns? If getRootNavById
shall the new method, it should returns the same root as getRootNav()
if argument is undefined.
Please help!