2

我正在开发一个 ionic 2 移动应用程序,我发现当我通过侧面导航面板访问页面时,它没有在特定页面上提供自动生成的后退按钮,而当我以正常遍历形式一页一页地访问该页面时然后该页面可通过后退按钮使用。我怎样才能从侧面导航面板菜单中获得后退按钮,请建议。

<ion-header>

  <ion-navbar color="primary">
  <button ion-button menuToggle>
      <ion-icon name="menu"></ion-icon>
    </button>
    <ion-title>dashboard</ion-title>
  </ion-navbar>

4

1 回答 1

1

如果您在创建项目时创建了 sidemenu 应用程序,您可以在app.component.ts中看到以下代码

constructor(public platform: Platform, public statusBar: StatusBar, public splashScreen: SplashScreen) {
    this.initializeApp();

    // used for an example of ngFor and navigation
    this.pages = [
      { title: 'Home', component: Createpage}
    ];

  }

  initializeApp() {
    this.platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      this.statusBar.styleDefault();
      this.splashScreen.hide();
    });
  }

  openPage(page) {
    // Reset the content nav to have just this page
    this.nav.setRoot(page.component);
  }

正如您在 openPage 函数中看到的那样,它将页面组件设置为根,因此您看不到后退按钮,而是看到打开侧边菜单的汉堡包图标

现在

如果您仍然希望使用后退按钮从侧面菜单打开页面,您可以执行以下操作

openPage(page) {
    // Reset the content nav to have just this page
    // we wouldn't want the back button to show in this scenario
    if(page.component == HomePage){
      this.nav.setRoot(HomePage);
    } else {
      this.nav.push(page.component);
    }
  }

在上面的代码中,您检查它是否是后退按钮组件(您希望使用后退按钮打开),如果是真的,您可以将其设置为push而不是setRoot

评论以获得更多说明

于 2017-08-16T08:32:17.157 回答