首页 > 解决方案 > 如何在 IONIC 4 中设置 rootPage

问题描述

这就是我现在所拥有的,而且似乎真的找不到我的问题的正确答案,我到处都看过,所以也许知道的人可以帮助我?我如何像在 ionic 3 中一样将 RootPage 设置为 Ionic 4,因为我尝试了一切,这就是尝试剩下的

import {Component, ViewChild} from '@angular/core';
import {NavController, Platform} from '@ionic/angular';
import {SplashScreen} from '@ionic-native/splash-screen/ngx';
import {StatusBar} from '@ionic-native/status-bar/ngx';
import {Router} from '@angular/router';
import {GettingStartedPage} from './getting-started/getting-started.page';

@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
})

export class AppComponent {
@ViewChild(NavController) nav: NavController;
rootPage;


constructor(
    private platform: Platform,
    private splashScreen: SplashScreen,
    private statusBar: StatusBar,
    private NavCtrl: NavController) {
    this.initializeApp();
}

// Eindigt constructor

initializeApp() {
    this.platform.ready().then(() => {
        this.splashScreen.hide();
        // set status bar naar onze app kleur
        this.statusBar.backgroundColorByHexString('#E84B56');
    });
}

openPage(page) {
    // Reset the content nav to have just this page
    // we wouldn't want the back button to show in this scenario
    this.rootPage.navigateRoot('/getting-started');

}
}

标签: angularionic-frameworkwebpagerootionic4

解决方案


从 Ionic 4 开始,您使用 Angular Routing。如果您想/getting-started成为您的根页面,请进入app-routing.module.ts并编辑路线。如果您没有 on,请创建一个指向您的 Page 的 Route 并将其重定向path: ''到 to /getting-started

所以决赛app-routing.module.ts可能是:

const routes: Routes = [
    {path: '', redirectTo: 'getting-startet', pathMatch: 'full'}, //Root Path redirect to your getting-started path
    {path: 'getting-started', loadChildren: './getting-started/getting-started.module#GettingStartedPageModule'}, // when hit the getting-startet path, load the page
];

@NgModule({
    imports: [RouterModule.forRoot(routes)],
    exports: [RouterModule]
})
export class AppRoutingModule {
}

推荐阅读