Search code examples
navigationionic2back-button

How to avoid back button generated by [navPush] (Handling generated back Button)


I have a home page which is my first screen.

after i navigate to some pages On clicking a button i need to get back to the home page without back button

for navigation i use [navPush]='pageName';

This navPush automatically generates back button. But i dont need the back button when i go back.

I tried navPop it is working fine but the problem is it takes to the next page only .

Example

if i have 10 pages from 10th page i have to come to 1st page using ionic navPop i am not able to achieve this .

When i tried with navPush i am able to get back but i am not able to avoid the back button in homepage.

Question:

Is there anything else i am missing how to avoid the back button generated using navPush or navPop


Solution

  • On clicking a button I need to get back to the home page without back button

    Please take a look at this working plunker.

    1. You can use the setRoot() method like this:

      this.navCtrl.setRoot(HomePage);
      
    2. If you really need to use the push method instead of the setRoot, you can also try with the showBackButton() method from the ViewController

      showBackButton(Set): Set if the back button for the current view is visible or not. Be sure to call this after ionViewWillEnter to make sure the DOM has been rendered.