网站搜索

angular - 在 ionic 4 中重写工具栏返回按钮的操作


在 Ionic 3 中可以通过 navbar.backButtonClick =()=>{} 覆盖返回按钮的操作

由于在 Ionic 4 中 navbar、navcontroller 不再存在

如何以类似的方式重写 ion-back-button 的返回操作

答案#1

你可以在你的 AppComponent 类上使用以下代码。

this.platform.backButton.subscribeWithPriority(9999, () => {
    // You decide what happens 
});

答案#2

我的朋友,这样就行了.. 安卓和 iOS 哈哈哈

<ion-header>
    <ion-toolbar>

        <ion-buttons slot="start" style="position: relative;">
            <ion-back-button></ion-back-button>
            <div (click)="backButtonClick()" style="position: absolute;left: 0;top: 0;width: 100%;height: 100%;background-color: transparent;z-index: 1000;"></div>
        </ion-buttons>

    </ion-toolbar>
</ion-header>