Ionic ngrx nav_controller


#1

Im using Ionic3 and ngrx. Lets say I have a component from which an action is dispatched… Whats the best way to navigate to a new page after it has been processed? any suggestions on what is best? (Ideally not by modifying the store for this purpose).
Thanks!


#2

ideally you want to listen to the changes in the actions stream to determine if it is okay to transition to the next page. In this project https://github.com/aaronksaunders/ionic4-ngrx-firebase

I listen for specific actions to determine what message to display in the dialog

    // check and see if we have successfully added an object, if so
    // display success alert and clear flag on state
    this.store.pipe(select(selectDataAction)).subscribe(action => {
      if (action) {
        console.log(action);

        if (action.action) {
          let message = "";
          switch (action.action) {
            case CREATE_FIREBASE_OBJECT_SUCCESS:
              message = "Object Created Successfully";
              break;

            case DELETE_FIREBASE_OBJECT_SUCCESS:
              message = "Object Deleted Successfully";
              break;

            case UPDATE_FIREBASE_OBJECT_SUCCESS:
              message = "Object Updated Successfully";
              break;

            default:
              break;
          }
          this.doToast(message);
          this.store.dispatch(new All().clearSuccessAction());
        }
      }
    });
  }

#3

Thanks, I ended up firing an action like “ACTION_SUCCESS” and listening to it in the page_component where i implemented the navigation logic.


#4

glad it worked out, sometimes these things seem way more complicated than they should be