angular - 如何在 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');
}
}
解决方案
从 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 {
}
推荐阅读
- c - 在 Mac 上使用 VS Code 打开 .txt 文件
- python - FigureCanvaQtAgg : 区分左右点击
- c# - 无法从 URL Xamarin 表单下载图像
- angular - 如何访问 ng-content 投射的原生元素
- flutter - Flutter 在构建复杂小部件时显示加载指示器
- sql-server - SQL将多个值连接到多个值
- wso2 - wso2,配置header携带Bearer token,不起作用
- ios - iOS13 上的 Paypal iOS SDK UI 问题
- python - Django 从 1.8 升级到 1.9 在 init 中的模型导入中断
- docusignapi - 谁的凭据用于授权代码授予?