back menu Ionic v3 button

Asked

Viewed 304 times

0

Good morning to all.

I have a question, when I click on the menu and choose one of the options, it loads a new page, but it seems to me that in the stack is the previous page that contains the access to the menu to which I clicked..

Ex: Page Home - contains the menu, I click on it and I have options like: Page 1, Page 2 ...

I am testing through the browser.. By clicking on the Page 1 option on the menu, instead of pressing the Page 1 stack, it does not load. Home..

http://localhost:8100/home -> should not change to http://localhost:8100/page1 ?

I understand how the stack works as I navigate by page, but when I navigate the menu it seems to change... or I’m completely wrong or I don’t even know..

Therefore, the back button on Page 1 does not appear. for me to go back to Home page..

and I need this backbutton, how do I fix it????? Please help me please.

and thanks in advance!

1 answer

0

In the menu function that opens a new page, check the following:

If the function calls a new page like this (below), you will reset the stack and put the page you clicked as Pageroot (first) from the stack. In this case you cannot go back to the homepage because the first page of the stack will be Page1

this.nav.setRoot('Page1');

If so (below), you will be stacking another page in the stack that already exists. If you are on the Homepage, open the menu and click on Page1, then you will be able to return to the Homepage with backButton.

this.nav.push('Page1');

The problem with this second example is that on any page you are, for example, you have navigated to Homepage > Page1 > Page2. On Page2 you open the menu and click on Page1. You will be re-stacking Page1 on the stack. Ex. Homepage > Page1 > Page2 > Page1.

----- Edit: -----

In the Navcontroller documentation I found this:

openPage(page: string) {
    this.nav.setPages(['HomePage', page]);
}

You can always set the Homepage as the first of the stack. Then the backButton will always appear and return to the Homepage.

  • 1

    The last one gave Gesiel Rosa certificate.. You were indispensable to this resolution my dear friend. Thank you very much! Saved the week... mania of not reading the documentation!!!! I need to learn to read the documentation.. Despair and lack of patience are wasting our time, and I’m glad we have this community and we can find qualified people. Strong hug and thanks again.

  • Ionic documentation is very complete. Hugs

Browser other questions tagged

You are not signed in. Login or sign up in order to post.