admin管理员组文章数量:1320786
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');
}
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');
}
Share
Improve this question
asked Jul 18, 2017 at 7:43
Varuni N RVaruni N R
8023 gold badges13 silver badges32 bronze badges
5
- 1 May I ask, why don't you read the navigation-related docs in the first place? – sebaferreras Commented Jul 18, 2017 at 7:50
- Sorry i was keen on looking for button click. Did not think there could be a way to redirect from nav on button click – Varuni N R Commented Jul 18, 2017 at 7:51
- 1 Np, just mentioned that because navigation in Ionic is not as simple as it may look, so you'd definitely need to read the docs to avoid some bugs/issues. There are a lot of things to consider for your question, like is that the root ponent?, do you want to set that page as root, or just push it?, and so on... – sebaferreras Commented Jul 18, 2017 at 7:53
- 1 Okay thank u for the suggestion – Varuni N R Commented Jul 18, 2017 at 7:54
- 1 @sebaferreras - Hey found answer for setting as root ponent and just pushing it. Anyway thanks – Varuni N R Commented Jul 18, 2017 at 8:05
1 Answer
Reset to default 4Use 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."
本文标签: javascriptRedirect to other page in ionic framework v3Stack Overflow
版权声明:本文标题:javascript - Redirect to other page in ionic framework v3 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742078432a2419548.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论