These are chat archives for angular/angular-2-ionic-2

23rd
Nov 2017
Han van Venrooij
@irundaia
Nov 23 2017 08:43

Hi guys,

I've got an app that has a tabs page when you're logged in. When logging out, I want to navigate away from the tabs page. Is there some sort of best practice for doing this?

I'm currently using: this.app.getRootNavs()[0].setRoot(LoginPage)
UncertaintyP
@UncertaintyP
Nov 23 2017 08:53
Is there a specific reason you can't use the Nav/NavController?
Han van Venrooij
@irundaia
Nov 23 2017 08:55
We're using the ngrx/effects library for all side effects. I don't think we can inject the Nav in there.
UncertaintyP
@UncertaintyP
Nov 23 2017 08:55
Oh yeah I'm using Ngrx and doing it the same way there, dunno if its the "best" though :D
Han van Venrooij
@irundaia
Nov 23 2017 08:56
I'm getting some issues though...
If I push to the root nav, and I try to pop from it, I'm getting: "navigation stack requires at lease one root page"
:<
It seems like pushing to the root nav does not change the active nav
Or, I'm picking the wrong one...
xD
UncertaintyP
@UncertaintyP
Nov 23 2017 09:00
Hmm I only use it for setRoot and do the other stuff in Ionic's NavController, had no problems with this approach
What functions do you call that cause the error?
UncertaintyP
@UncertaintyP
Nov 23 2017 09:08
There is a function on app that loops through the rootNavs and tries to find a poppable view so you could try this.app.navPop()
Han van Venrooij
@irundaia
Nov 23 2017 09:10
Okay so the app has a tabs page when logged in.
On one of its tabs we've got a button to go to the SettingsPage. This SettingsPage should be shown outside of the tabs page. To achieve this, we call this.app.getRootNavs().push(SettingsPage)
On this this page we need to navigate one step deeper, so here we use a regular NavController.push.
From that page we need to pop back to the SettingsPage
I'm not sure whether that helps.. :<
The app.navPop works though :)
Thanks a bunch :)
UncertaintyP
@UncertaintyP
Nov 23 2017 09:16
I am honestly surprised that this.app.getRootNavs().push(SettingsPage) works because you never change the actual rootNavs array but a generated clone of it ^^
Han van Venrooij
@irundaia
Nov 23 2017 09:47
I forgot a [0] there.
It should be this.app.getRootNavs()[0].push(SettingsPage)
UncertaintyP
@UncertaintyP
Nov 23 2017 09:48
Ah this makes more sense :D
Han van Venrooij
@irundaia
Nov 23 2017 09:56
xD Thanks again
UncertaintyP
@UncertaintyP
Nov 23 2017 09:56
Sure no problem :D