Ionic 2 - Navigation (ion-menu) - Caching views

Hi everyone,

I’m re-coding an app from v1 to v2, and I’m facing an issue : on v1 when implementing an ionic menu, the views were cached and when you get back from one to another, the page was displayed as you left it before. But on v2, some examples are showing us how to implement ion-menu : only with the NavigationController and the push method (so every time I click on a view, a new View of it is called and the previous state of the view is erased). I tried to “cache” my views manually, but it seems not working. Here is my code :

openPage(page) {
    if(this.activePage != page) {
      if(this.nav.indexOf(page) == -1) {
      } else {
      this.activePage = page;

Thanks in advance for all your answers guys !!

A dev in need

You should design your app so that it doesn’t care what gets cached when. That’s sort of part of the contract of caches. If you have data that needs to be persisted, generally an injected service that holds it is the most typical pattern.

Okay :slight_smile: thank you @rapropos , I will look this way.

Hey @rapropos, I recoded my application with shared providers and it works well ! I just have one more issue … I have a MapBox map and it becomes blank when I change my page in my menu (on navController.push a new instance of the Page is called and the HTML is reinitialized :confused: ). Do you have any solution for “storing” this map ?