Reputation: 143
I am building an application with Ionic 2. Once successfully logged in, the home page is pushed on top of the login page. The only problem with this is that the "back" icon appears at the top of the home page. I want a way of redirecting to the home page upon login such that the "back" icon does not appear.
Thanks
Upvotes: 4
Views: 10281
Reputation: 529
I would recommend setting the root of the navigation stack by calling this.navCtrl.setRoot(YourDesiredPageClassHere)
on the NavigationController instance instead of calling this.navCtrl.push(YourDesiredPageClass)
. This sets the root navigation page to YourDesiredPageClass, without any pages it can navigate back to, thus no back button.
You could also disable the back button programmatically by calling showBackButton(false)
on the ViewController instance of the page you are navigating to like so:
import { NavController, ViewController } from 'ionic-angular';
export class Page {
constructor(
private navCtrl: NavController,
private viewCtrl: ViewController
) { }
ionViewWillEnter() {
this.viewCtrl.showBackButton(false);
}
}
Or disable the back button in your HTML using the hideBackButton
attribute (this could also be hide-back-button
) like so:
<ion-navbar hideBackButton="true">
<ion-title>Title</ion-title>
</ion-navbar>
Upvotes: 2
Reputation: 3310
You have to setRoot
. That way the new component is the root, which in your case would be the HomePage component.
this.navCtrl.setRoot(HomePageComponent, {}, {animate: true, direction: 'forward'});
Upvotes: 10