Redirect to another page in ionic framework v3
I am new to ionic structure. I am trying to redirect to another page on a button click in Ionic wireframe version 3. I don't have enough sources. I tried functions location()
and go()
, but it didn't work.
This is my code in the newpage.html file:
<button ion-button block (click)="click()">Click me</button>
This is my code in newpage.ts:
click() {
this.go('/HomePage');
}
source to share
Use [NavController][1]
from ionic-angular
. Its push()
-method pushes the new view onto the navigation stack. This means that you can use the method NavController
pop()
to return 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 <ion-navbar>
, the back button will automatically be added to the clicked view."
source to share