How to push a list of pages into nav stack?


#1

Hi, I am a beginner of Ionic2 and here is my situation:

I am trying to build an application for my research, I have many pages, ex: page1, page2, page3, page4.

And I am working on page3, so that the nav stack will contain page1 -> page2 -> page3.

For some reason, the app was crashed or stopped and I want to resume to page3 when I open the app.

I have done in resume to page3 but in this case, the nav stack just contain only page3 and when I click on “Back” button, it back to the root page, not to page2 -> page1.

So, anyone have any idea or solution for my case?

Thank you very much.


#2
nav.setPages(pagesArray, navOpts);

#3

Thank you very much for your quick reply, in this case, I use a MasterPage that contain many Detail Pages, how can I use that method?

I have create an array, ex: listPages = [page1,page2,page3] and use nav.setPages(listPages), but it does not work, I think I have missed something :frowning:


#4

If by Detail Pages you mean a single page that renders different content (such as the basic list tutorial app) then you need to pass the page as a nav parameter.

eg.

nav.setPages(
    {page: MasterPage},
    {page:DetailsPage, params: {id: 5}}
);

#5

Thank you very much for your help, I will try


#6

Thank you very much for your help @beck24, but in my case, I have to modify a little bit, and here is my code:

// Because I have a MasterPage that contain all child pages, so I just have to use only one MasterPage and then pass to params all the pages that I have push into listPages

let items = [];
for (let i = 0; i < frm.listPages.length; i++) {
      items.push(
          { page: MasterPage, params: { currentPage: frm.listPages[i] } }
     );
}
nav.setPages(items);