Varuni N R
Varuni N R

Reputation: 802

Redirect to other page in ionic framework v3

I am new to ionic framework. I am trying to redirect to other page on button click in ionic framework version 3. I did not get enough source on this. I tried location() and go() functions but it did not work.

This is my code in newpage.html :

<button ion-button block (click)="click()">Click me</button>

This is my code in newpage.ts :

  click() {
  this.go('/HomePage');
  }

Upvotes: 4

Views: 16012

Answers (1)

robbannn
robbannn

Reputation: 5013

Use the [NavController][1] from ionic-angular. Its push()-method pushes a new view onto the navigation stack. This means that you can use the NavController pop()-method to go back to this page.

import { NavController } from 'ionic-angular';
// IMPORT HOMEPAGE IF NOT LAZY-LOADED
import { HomePage } from '../home/home';

export class NewPage{
    constructor(private navCtrl:NavController){}

    // IF LAZY-LOADED
    click(){
        this.navCtrl.push('HomePage');
    }

    // IF NOT LAZY-LOADED
    click(){
        this.navCtrl.push(HomePage);
    }
}

According to the docs: "If the page has an <ion-navbar>, a back button will automatically be added to the pushed view."

Upvotes: 4

Related Questions