Monday, June 3, 2024
71
rated 0 times [  74] [ 3]  / answers: 1 / hits: 15752  / 7 Years ago, tue, july 18, 2017, 12:00:00

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');
}

More From » ionic-framework

 Answers
17

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.


[#57049] Friday, July 14, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
savanar

Total Points: 237
Total Questions: 105
Total Answers: 99

Location: Wales
Member since Mon, May 17, 2021
3 Years ago
;