Ionic nav controller pop flow

Issue

I have a doubt about how can make this.

// Page 0.1
this.navController.pop(); 

// Page 0
ionViewWillEnter() {
  console.log("Im here");
}

I have a page that clicking a button I can go back to Page 0. But each time that I get back it doesn’t enter inside ionViewWillEnter(). I need to enter to evaluate some new changes in data to print in screen. Any idea?

Environment:

Ionic CLI                     : 6.12.2
Ionic Framework               : @ionic/angular 5.5.1
@angular-devkit/build-angular : 0.1000.8
@angular-devkit/schematics    : 10.0.8
@angular/cli                  : 10.0.8
@ionic/angular-toolkit        : 2.3.3

Solution

There must be something else going on because it should always execute the ionViewWillEnter when it’s about to enter to the page.

Please take a look at this Stackblitz demo

Demo

The code of the home page:

import { Component } from "@angular/core";
import { NavController, ViewWillEnter } from "@ionic/angular";

@Component({
  selector: "app-home",
  templateUrl: "./home.page.html",
  styleUrls: ["./home.page.scss"]
})
export class HomePage implements ViewWillEnter {
  constructor(private navController: NavController) {}

  ionViewWillEnter() {
    console.log("Will enter!");
  }

  public openDetailsPage(): void {
    this.navController.navigateForward("/details");
  }
}

And the details page:

import { Component } from "@angular/core";
import { NavController } from "@ionic/angular";

@Component({
  selector: "app-details",
  templateUrl: "./details.page.html",
  styleUrls: ["./details.page.scss"]
})
export class DetailsPage {
  constructor(private navController: NavController) {}

  public goBack(): void {
    this.navController.pop();
  }
}

Answered By – sebaferreras

Leave a Comment