如果您在创建项目时创建了 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
评论以获得更多说明