Ionic 2 App Re-Display page on start-up


#1

Does anyone know how I could either a) force my app to re-start from scratch every time the user launches the app or b) re-display a particular page when the app re-starts e.g on resume.

I have a tabbed Ionic 2 application with a login page which I display on start-up, and then when the user logs in my TabsPage is pushed onto the nav. I want to get that initial login page to display every time the user opens the app, rather than have the application open up with the tabs already open.

In my app.js I have:

class MyApp {
constructor(platform: Platform) {
this.root = LoginCtrl;

platform.ready().then(() => {
  this.bindEvents();
});

}

bindEvents: function () {
document.addEventListener(‘resume’, this.onResume, false);
}

onResume: function () {
console.log(“on resume”);
this.root = LoginCtrl;
}

}

This doesn’t work i.e the LoginPage is not re-displayed although the onResume event is firing.

What would I need to do to get that to work?


#2

Your app.html should have something like

<ion-nav id="nav" [root]="rootPage" #content swipe-back-enabled="false"></ion-nav>

then if you set rootPage to something useful in your app.js, that’s the first place the app will go when you initialize it.

this.rootPage = LoginPage;

Does that work for you?


Cordova on resume and native plugins
#3

@richardshergold Did you figure out how to do this? I need to do this as well.


#4

I can’t remember to be honest. I think possibly not.


#5

This worked for me:

      // Listen for the app coming from the background into the foreground
      document.addEventListener('resume', () => {
        setTimeout(() => {
          this.onResume();
        });
      });

#6

You can also use the Platform API form Ionic: http://ionicframework.com/docs/v2/api/platform/Platform/

this.platform.resume.subscribe(e => {
    this.onResume();
});