2017-02-17 88 views
2

我在Ionic 2框架中非常新。我想知道,我如何使用網址在離子應用程序中導航。類似的方式導航是在Angular 2應用程序中完成的。Ionic 2:使用URL導航

比方說,我想有本地主機IntroPage:8100 /前奏與登錄按鈕並按下按鈕後,我想重定向到首頁本地主機:8100 /家

localhost:8100/intro -> localhost:8100/home 

回答

2

您可以使用ionic2的DeepLinker

在ionic2中,您可以使用this.navigator.push(SomeComponent)進行導航。但是,如果您想要更改網址,您需要爲它們定義deeplinker,例如:

imports: [ 
IonicModule.forRoot(MyApp, {}, { 
    links: [ 
    { component: HomePage, name: 'Home', segment: 'home' } 
    ] 
}) 
] 
0

的文件說:(https://ionicframework.com/docs/v2/api/navigation/NavController/) 你仍然不能使用UI-S參考樣離子1..but僅this.navigation.push(「家」)......這意味着你必須做在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'); 
    } 
}