在我的app.component.ts
我将rootPage
设置为LoginComponent
,如下所示:
import { Component } from '@angular/core';
import { Platform, IonicPage } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { Deeplinks} from '@ionic-native/deeplinks';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
rootPage:any = 'login';
constructor(platform: Platform, statusBar: StatusBar, splashScreen:
SplashScreen, private deeplinks: Deeplinks) {
platform.ready().then(() => {
statusBar.styleDefault();
splashScreen.hide();
});
}
}
然后在我的LoginComponent
中使用
this.navCtrl.setRoot('friend-list');
friend-list
是由
@IonicPage({
name: 'friend-list',
segment: 'friend-list'
})
问题是我总是在我的浏览器中有静态localhost之类的
localhost:8100/#/login
,只要我在我的应用中,但是如果我输入localhost:8100/#/friend-list
应用就可以正常使用该应用。什么可能导致这个问题?
答案 0 :(得分:0)
这个问题使我发疯,我终于以这种方式解决了。
在“ app.module.ts”中,我导入“ DeepLinker”和“ DeepLinkConfig”,并将“链接”数组添加到“导入”数组中,以指定我所有页面的名称。像这样:
import { DeepLinker, DeepLinkConfig } from 'ionic-angular';
imports: [
IonicModule.forRoot(MyApp, {
mode: 'md',
animate: 'ios-transition'
}, {
links: [
{ component: HomePage, name: 'page-home', segment: 'page-home' }
]
})
]
接下来,在具有导航按钮的页面上,我设置一个click事件以调用以下函数:
goToURL() {
//'page-home' has to be the value you provided for "name" in the "link" array above
this.events.publish('page:navigated', 'page-home');
}
最后,在我的“ app.component.ts”中,导入Event和NavController(如果尚不存在),并订阅刚刚从上面的函数发布的事件:
import { Events, NavController} from 'ionic-angular';
constructor(public events: Events) {}
events.subscribe('page:navigated', (page) => {
this.navCtrl.setRoot(page);
});