Angular 离子2:使用URL导航
我是离子2框架的新手。我想知道,如何使用URL在ionic应用程序中导航。类似于Angular 2应用程序中的导航方式 假设我想在localhost:8100/intro上使用登录按钮设置IntroPage,按下按钮后,我想重定向到localhost:8100/home上的主页Angular 离子2:使用URL导航,angular,ionic2,Angular,Ionic2,我是离子2框架的新手。我想知道,如何使用URL在ionic应用程序中导航。类似于Angular 2应用程序中的导航方式 假设我想在localhost:8100/intro上使用登录按钮设置IntroPage,按下按钮后,我想重定向到localhost:8100/home上的主页 localhost:8100/intro -> localhost:8100/home 正如文档所述:(https://ionicframework.com/docs/v2/api/navigation/NavC
localhost:8100/intro -> localhost:8100/home
正如文档所述:(https://ionicframework.com/docs/v2/api/navigation/NavController/
)
您仍然不能像在ionic 1.中那样使用ui sref,但只能使用这个.navigation.push('home')。。。这意味着您必须在html上执行一个函数(可能是(单击)=“myfunc()”)来调用ts文件中的导航
import { Component, ViewChild } from '@angular/core';
import { NavController } from 'ionic-angular';
@Component({
template: '<ion-nav #myNav [root]="rootPage"></ion-nav>'
})
export class MyApp {
@ViewChild('myNav') nav: NavController
public rootPage = TabsPage;
// Wait for the components in MyApp's template to be initialized
// In this case, we are waiting for the Nav with reference variable of "#myNav"
ngOnInit() {
// Let's navigate from TabsPage to Page1
this.nav.push('home');
}
}
从'@angular/core'导入{Component,ViewChild};
从'ionic angular'导入{NavController};
@组成部分({
模板:“”
})
导出类MyApp{
@ViewChild('myNav')导航:导航控制器
公共rootPage=TabsPage;
//等待MyApp模板中的组件初始化
//在本例中,我们正在等待参考变量为“#myNav”的Nav
恩戈尼尼特(){
//让我们从选项卡导航到第1页
本导航推送(“主页”);
}
}
您可以使用ionic2
在ionic2中,只需使用this.navigator.push(SomeComponent)
即可导航。但如果您想要更改url,则需要为其定义deeplinker,如:
imports: [
IonicModule.forRoot(MyApp, {}, {
links: [
{ component: HomePage, name: 'Home', segment: 'home' }
]
})
]