离子路径路由(如 Angular2 中的 RouterModule)
Ionic path routing (like RouterModule in Angular 2)
(前言:我来自 C#/WPF 背景,一般来说是 Web 开发的新手 - 请耐心等待!)
使用 Angular 2,我可以这样定义我的路线:
RouterModule.forChild([
{ path: 'contacts', component: ContactsComponent }
])
然后,在一些html中,我可以使用routerLink语法来引用它:
routerLink='/contacts'
效果很好,最终它允许我用绑定替换字符串,这样我就可以在运行时获取路径,从而允许数据确定导航结构。
现在,我正尝试在 Ionic 2 中做一些类似的事情,但如果可能的话,这对我来说并不明显。我已经了解了如何使用 [navPush] 通过深层链接绑定到页面(就像这个人所做的那样:http://plnkr.co/edit/syUH0d6SJd2gAjqaPLwr?p=preview),但这需要在要使用它的组件中提前定义页面.
Ionic 的导航结构支持这个吗?
经过大量挖掘,我发现我做错了什么。
以下是使用 Ionic v2 deep linking 将 link 定向到路径的方法:
在 app.module.ts 导入中添加:
IonicModule.forRoot(MyApp, {}, {
links: [
{ component: ContactsPage, name: 'ContactPageName', segment: 'contacts' }
]
确保也将 ContactsPage 添加到声明和 entryComponents。
然后,在发起导航的页面html中,声明式使用,像这样
navPush="ContactPageName"
请注意,您使用的是直接 link!
的名称
在我的例子中,我从 json 文件中获取项目列表,因此像这样循环遍历它们:
<ion-item *ngFor="let contact of contacts" detail-push>
<button ion-button navPush="{{contact.link}}">Go</button>
</ion-item>
我的 json 文件包括:
"link": "ContactPageName"
希望对其他人有所帮助!
(前言:我来自 C#/WPF 背景,一般来说是 Web 开发的新手 - 请耐心等待!)
使用 Angular 2,我可以这样定义我的路线:
RouterModule.forChild([
{ path: 'contacts', component: ContactsComponent }
])
然后,在一些html中,我可以使用routerLink语法来引用它:
routerLink='/contacts'
效果很好,最终它允许我用绑定替换字符串,这样我就可以在运行时获取路径,从而允许数据确定导航结构。
现在,我正尝试在 Ionic 2 中做一些类似的事情,但如果可能的话,这对我来说并不明显。我已经了解了如何使用 [navPush] 通过深层链接绑定到页面(就像这个人所做的那样:http://plnkr.co/edit/syUH0d6SJd2gAjqaPLwr?p=preview),但这需要在要使用它的组件中提前定义页面.
Ionic 的导航结构支持这个吗?
经过大量挖掘,我发现我做错了什么。 以下是使用 Ionic v2 deep linking 将 link 定向到路径的方法:
在 app.module.ts 导入中添加:
IonicModule.forRoot(MyApp, {}, {
links: [
{ component: ContactsPage, name: 'ContactPageName', segment: 'contacts' }
]
确保也将 ContactsPage 添加到声明和 entryComponents。
然后,在发起导航的页面html中,声明式使用,像这样
navPush="ContactPageName"
请注意,您使用的是直接 link!
的名称在我的例子中,我从 json 文件中获取项目列表,因此像这样循环遍历它们:
<ion-item *ngFor="let contact of contacts" detail-push>
<button ion-button navPush="{{contact.link}}">Go</button>
</ion-item>
我的 json 文件包括:
"link": "ContactPageName"
希望对其他人有所帮助!