Ionic 4 Disable iOS Swipe Back in ONE PAGE ONLY

Hello everyone,

I want to disable iOS in one page only and not globally, so let’s say a user checkouts and makes the payment, i don’t want the user to go back to where he was after he gets the receipt. I want the user to stay to that page without the possibility to swipe back, in android i have already disabled the hardware button while in iOS i am struggling a bit.

i have added to app.module:

IonicModule.forRoot({ swipeBackEnabled: false })

which disables the swipe back globally and thats what i don’t want, i also tried this one:

Article about disabling swipe back

I followed it and still i could not reach what i want,

I also don’t get what the user says at the end:

The current implementation only works with a single IonRouterInstance in the application but it can be enhanced with support for additional instances if you require that in your own application.

What does he mean by WORKS WITH A SINGLE?

Thank you very much, any help would be appreciated.

private routerOutlet: IonRouterOutlet,

this.routerOutlet.swipeGesture = false;
try this in ngOnInit or ionViewWillEnter

3 Likes

that indeed works, thank you :), remember i also have to do TRUE when i leave page with ionViewWillLeave.

1 Like

In my case the solution above proposed was the solution to the problem but I had to avoid that the app left the home page to the login page when the user swiped back, to avoid this in ios I had to put this code in the navigation root (side menu or navigations tabs).

import { IonRouterOutlet } from '@ionic/angular';

  constructor( private routerOutlet: IonRouterOutlet) {}

 ngOnInit() {
    this.routerOutlet.swipeGesture = false;
  }
1 Like

Hi, I am facing this problem as well. But i tried to put
private routerOutlet: IonRouterOutlet,

this.routerOutlet.swipeGesture = false;
try this in ngOnInit or ionViewWillEnter

to my home.page.ts it doesnt work.

I enable swipeGesture by putting
<ion-router-outlet id=“main-content” [swipeGesture]=“true” animated=“true”>
at app.component.html?
Any suggestion?

Environment is Ionic 4 angular

Hi i have the same issue is there anyone to help me please?

Does not work for me please help me to fix this issue

SwipeGesture is enabled by default, when you go inside the page you disable it, and when you leave that page you enable it again.

try this, this is working for me on the latest ionic version also:

import { IonContent, IonRouterOutlet } from '@ionic/angular';

 constructor(
    private routerOutlet: IonRouterOutlet
  ) {
    
  }

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

ionViewDidLeave(){
    this.routerOutlet.swipeGesture = true;

  }
1 Like