Ionic 5 - How can i disable "back swipe" in IOS?

Hi,

I need to disable ios swipe on specific pages, but I can’t find a way to do it.

I also tried some solutions, but none is compatible with Ionic 5. For example, in ionic 2 you can use:

<ion-view can-swipe-back="false">

I need the equivalent from ionic 5, applicable to <ion-content> tags

In Ionic 5, i could disable swipe on ALL pages by adding the following to the app.module, but i need a way to disable only in specific pages:

IonicModule.forRoot({
            swipeBackEnabled: false
        }),
Ionic: v5.16.0
Angular: v8.2.8

Thanks!

2 Likes

Inject IonRouterOutlet in app component, and disable it onInit

example:

constructor(private routerOutlet: IonRouterOutlet) {
}
ngOnInit() : void {
this.routerOutlet.swipeGesture = false;
}
2 Likes

It will prevent all swipe back actions on all child routes. How to disable on certain page?

1 Like

One can disable gesture in ionViewDidEnter and reenable it again in ionViewWillLeave

ionViewDidEnter() {
  this.routerOutlet.swipeGesture = false;
}
ionViewWillLeave() {
  this.routerOutlet.swipeGesture = true;
}