简体   繁体   English

ion-router-outlet 未显示组件但路由器插座显示

[英]ion-router-outlet not showing component but router-outlet does

I'm experimenting with ionic and angular routing and have encountered some issues.我正在尝试使用 ionic 和 angular 路由,但遇到了一些问题。 I have two components, first and second, and the app-root component.我有两个组件,第一个和第二个,以及 app-root 组件。

app.component.html:应用程序组件.html:

<ion-app>
  <ion-header>
    <ion-toolbar color="primary">
      <ion-title>Router App</ion-title>
    </ion-toolbar>
  </ion-header>
  <ion-content>
    <ion-card>
      <ion-card-header>
        <ion-card-title>Click To Navigate</ion-card-title>
      </ion-card-header>
      <ion-card-content>
        <a routerLink="first-component" routerLinkActive="active"><ion-button>First</ion-button></a>
        <a routerLink="second-component" routerLinkActive="active"><ion-button>Second</ion-button></a>
      </ion-card-content>
    </ion-card>
  </ion-content>
  <ion-card>
    <ion-router-outlet></ion-router-outlet>
  </ion-card>
  
</ion-app>

and app-routing.module.ts和 app-routing.module.ts

import { NgModule } from '@angular/core';
import { PreloadAllModules, RouterModule, Routes } from '@angular/router';
import { FirstComponent } from './first/first.component';
import { SecondComponent } from './second/second.component';
import { HomeComponent } from './home/home.component';


const routes: Routes = [
  { path: 'first-component', component: FirstComponent },
  { path: 'second-component', component: SecondComponent },
  { path: 'home-component', component: HomeComponent },
  { path: '', component: HomeComponent },
];

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

The two components are simply这两个组件很简单

<p>componentName works!</p>

Now the issue I've got is the doesn't work and displays nothing when I click on the buttons to show the component.现在我遇到的问题是当我单击按钮以显示组件时它不起作用并且不显示任何内容。 But, if I use the normal angular the components display at the very bottom of the page, leaving a big gap in the middle.但是,如果我使用正常的 angular 组件显示在页面的最底部,中间会留下很大的空白。

I'm quite new to Angular and this is my second day playing around with Ionic so I'm not too sure where I've gone wrong.我对 Angular 很陌生,这是我玩 Ionic 的第二天,所以我不太确定哪里出了问题。

Let me know if any additional info is missing and I'll add it on.如果缺少任何其他信息,请告诉我,我会添加。

Thanks in advance!提前致谢!

Try to route like this.尝试像这样路由。 This is ionic default way.这是离子默认方式。 在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM