Angular 如何在IONIC 4中设置根页面
这就是我现在所拥有的,似乎真的找不到我的问题的正确答案。我到处都找过,也许有人知道可以帮助我?。我如何将像爱奥尼亚3中那样的RootPage设置为爱奥尼亚4,因为我尝试了所有东西,这就是尝试后剩下的东西Angular 如何在IONIC 4中设置根页面,angular,ionic-framework,webpage,root,ionic4,Angular,Ionic Framework,Webpage,Root,Ionic4,这就是我现在所拥有的,似乎真的找不到我的问题的正确答案。我到处都找过,也许有人知道可以帮助我?。我如何将像爱奥尼亚3中那样的RootPage设置为爱奥尼亚4,因为我尝试了所有东西,这就是尝试后剩下的东西 import {Component, ViewChild} from '@angular/core'; import {NavController, Platform} from '@ionic/angular'; import {SplashScreen} from '@ionic-nativ
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');
}
}
因为爱奥尼亚4号你使用了角度布线。如果希望
/getting started
成为您的根页面,请进入应用程序路由.module.ts
并编辑路由。如果您没有打开,请创建一个指向您的页面的路由,并将路径为“的路由重定向到/getting started
因此,最终的应用程序路由.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 {
}
我希望以下内容对您有所帮助:
constructor(private nav: NavController){}
private setRoot(){
this.nav.navigateRoot('/getting-started');
}
爱奥尼亚4号使用路线导航。您可以在
/src/app/app routing.module.ts
中找到路由的配置,即使您仍然可以在app.module.ts
文件中进行设置。引用,最基本的配置看起来有点像这样:
import { RouterModule } from '@angular/router';
@NgModule({
imports: [
...
RouterModule.forRoot([
{ path: '', component: LoginComponent },
{ path: 'detail', component: DetailComponent },
])
],
})
这里最简单的细分是路径/组件查找。当我们的应用加载时,路由器通过读取用户试图加载的URL来启动。在我们的示例中,我们的路由查找“”,它本质上是我们的索引路由。因此,我们加载LoginComponent。相当直截了当
如果要在初始加载时加载其他组件,则应使用