Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 71521

Issue with back button after navigating to page using menu from app.ts

$
0
0

@Gurpreet_singh wrote:

Using ViewChild and Nav option in Ionic2 I have implemented side menus. When I move from home page to any other page using side menu and then try to come back by clicking on the back button of my mobile(Android).
Apps get's closed. Can anyone pls help in this app. It's quite urgent

I have below code in app.html

```
<ion-menu [content]="content">
  <ion-header>
    <ion-toolbar>
      <ion-title>Menu</ion-title>
    </ion-toolbar>
  </ion-header>

  <ion-content>
    <ion-list>
      <button menuClose ion-item *ngFor="let p of pages" (click)="openPage(p)">
        {{p.title}}
      </button>
    </ion-list>
  </ion-content>

</ion-menu>

<!-- Disable swipe-to-go-back because it's poor UX to combine STGB with side menus -->
<ion-nav [root]="rootPage" #content swipeBackEnabled="false"></ion-nav>

in App.component.ts

import { Component, ViewChild } from '@angular/core';
import { Nav, Platform,AlertController,ToastController } from 'ionic-angular';

@Component({
  templateUrl: 'app.html'
})
export class MyApp {
  @ViewChild(Nav) nav: Nav;

  rootPage: any = HomePage;

  	openPage(page) {
		// Reset the content nav to have just this page
		// we wouldn't want the back button to show in this scenario
		this.nav.setRoot(page.component);
	}
  pages: Array<{title: string, component: any}>;
constructor(public platform: Platform) {
 this.pages = [
      { title: 'Home', component: HomePage },
      { title: 'About Us', component: AboutUs },
      { title: 'Feedback', component: Feedback },
      { title: 'Terms', component: Terms }
    ];
}

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 71521

Trending Articles