So, we have a Navigation Service which schedules the logic which page follows which and if a user needs to be logged in etc, quite complex. And now I want to use `navController.push(page), but from my understanding this can only be used from within app.ts, so should I put this in app.ts, or is there a better, more modular way?
app.ts:
public next(nextPageString) {
switch (nextPageString) {
case "browse":
this.nav.push(BrowsePage, {}, animationParams);
break;
case "goal-define":
this.nav.push(GoalDefinePage, {}, animationParams);
break;
...
Needless to say that above cases are endless. And I also did not find another way than to check for strings in order to get routing sorted out. Any ideas here are welcome.
@nottinhill … I am also working on a small side project basically to get familiar with ionic 2 and ngrx/store and ngrx/effects.
All good so far and I do get the concepts especially of the ngrx libs.
But I do struggle on how and where to put the navigation (aka the navCtrl.push(…) statements).
Consider the very easy flow for a login use case
user enters on one page its credentials
an ngrx actions is dispatched and a corresponding reducer changes the state in the store
a side effect for this login_action performs the API call and once completed returns new actions (as LOGIN_FAILURE or LOGIN_SUCCESS) which changes the state again.
My question is … where to put the logic to navigate after login API call to navigate the user to either something like a dashboard or to an error display page etc. (in case of false credentials …)
I tried to inject the nav controller into the effects- although it smells bad - but without success.
Any ideas? How did you manage to integrate navigation into an ngrx/ionic 2 app?
In this way I have also the navigation state in my store.
But I have an issue using the time-traversal in ngrx/store-devtools (redux plugin) basically it’s not working because the side-effects are not triggered for some reason.
Could be nice if some ngrx/ionic experts will find some time to write a module for that, like router-store-module for angular-route
Hi @devmao,
i’m trying to use your solution to store my routing actions on ngrx, but I get lost on resolvePage(navInfo.page), do you resolve the page from a string? Are you using the page class name?
I couldn’t find anywhere in Ionic Api Docs a method to retrieve a page component from string
I’ve just upgraded to Ionic v3 yesterday, but I’ve learned that if you use the @IonicPage() methodology you can refer to the page controls with their name, a string: perfect for storing in the redux store.
So I believe in the above code you do not need the resolvePage(), just make navCtrl.push(navInfo.page).