Ionic home page redirect is not working


#1

Code:

<ion-segment [(ngModel)]="segment" color="primary">
    <ion-segment-button value="Home" (click)="page_redirect('HomePage')" text-center> Home </ion-segment-button>
    <ion-segment-button value="Featured" (click)="page_redirect('FeaturedItemPage')" text-center> Featured </ion-segment-button>
    <ion-segment-button value="Category" (click)="page_redirect('CategoriesPage')" text-center> Category </ion-segment-button>
    <ion-segment-button value="User" user text-center> User </ion-segment-button>
</ion-segment>

page_redirect function

page_redirect(page){
    this.navCtrl.push(page);
}

Error:

Uncaught (in promise): invalid link: HomePage

Can anyone please tell me why ionic Homepage redirection is not working. CategoriesPage and FeaturedItemPage redirection working like charm.


#2

Hello,
I can see a few things you’re not doing right in this case,
this is what you have

page_redirect(page){
    this.navCtrl.push(page);
}

It should be

page_redirect(page){
    this.navCtrl.push('HomePage');
}

according to the method you’re using to pass your pages.
I will recommend you stop passing your pages as a string and always make sure you import the pages and declare them in your app.module.ts in this scenario, you can now import them in the desire page you want to call them in using this format:

<ion-segment-button value="Home" (click)="page_redirect(HomePage)" text-center> Home </ion-segment-button>```
Then now push the pages as

page_redirect(page){
this.navCtrl.push(HomePage);
}