Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic 4 router destroy page programmatically

I have a sign up flow on my app. At each step I don't want the user to be able to go to the previous page, however, ionic keeps these pages "alive" and the user is able to go back either by swiping from left to right or using the back button on their phone.

I transition each user using ionic's routing system:

 this.router.navigateByUrl('/invite');

I've also tried:

 this.router.navigate(['/invite']);

and:

 this.router.navigateByUrl('/invite', { skipLocationChange: true });

It's causing me a lot of problems at the moment and I've done quite a bit of Googling and couldn't find any solutions.

Is there a way using ionic's router system to destroy a page or disallow backward navigation on some pages? Any advice would be great. Thank you.

like image 484
Simon Avatar asked Sep 07 '26 23:09

Simon


2 Answers

You probably solved this already, however you can use the following as well:

this.router.navigateByUrl('/invite',{
 replaceUrl : true
});
like image 65
Cedrick Dayangco Avatar answered Sep 10 '26 16:09

Cedrick Dayangco


You have to use ionic navigation for that, they provide the functionalities.

Inject navController in constructor.

  constructor(
    private navCtrl: NavController,
  ) {
  }

Then use navigateroot, it will destroy previous page

this.navCtrl.navigateRoot('/home', { animated: true, animationDirection: 'forward' });

Go through below documentation

https://ionicframework.com/docs/angular/navigation

like image 21
Joshuva George Mohan Raj Avatar answered Sep 10 '26 16:09

Joshuva George Mohan Raj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!