私はAngular 2を初めて使用しており、他のテンプレート/コンポーネントを保持するビューコンポーネントをレンダリングしようとしています。これは私が/ homeルートでレンダリングしたいものです。 問題:/ homeルートに行くと、テンプレートをレンダリングするのではなく空白のページに移動します。コンソールにエラーはありません。ここに私のapp.module.tsのいくつかの部分があるAngular 2ルータがコンポーネントをレンダリングしないのはなぜですか?
<router-outlet></router-outlet>
<container>
<header-component></header-component>
<check-portfolio></check-portfolio>
<portfolio-carousel></portfolio-carousel>
<skill-section></skill-section>
<need-help></need-help>
</container>
home.component.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.scss']
})
export class HomeComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
:
は、ここに私のhome.component.htmlです。私は私が私のapp.component.htmlには何も必要かどうかわからないんだけど、それは空白です:ここでは
const appRoutes: Routes = [
{ path: 'home', component: HomeComponent },
{
path: '',
redirectTo: '/home',
pathMatch: 'full'
}
]
@NgModule({
declarations: [
AppComponent,
Container,
Header,
CheckPortfolioComponent,
PortfolioCarouselComponent,
SkillSectionComponent,
NeedHelpComponent,
FooterComponent,
AboutComponent,
HomeComponent,
TitleNavComponent,
],
imports: [
BsDropdownModule.forRoot(),
BrowserModule,
CarouselModule.forRoot(),
RouterModule.forRoot(
appRoutes,
{ enableTracing: true }
)
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
は私のindex.htmlです:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>LucidWebDream</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<script>
window.__theme = 'bs4';
</script>
<app-root></app-root>
</body>
</html>
私は私を入れて試してみましたブートストラップアレイにホームコンポーネントを追加しましたが、運はまったくありませんでした。
更新:それは場合に役立ちます。ここにgit repoは次のとおりです。
私はあなたのapp.component.htmlに router-outlet>を入れておきます。 –
guramidev
@Dream_Cap guramidevによると、あなたのapp.componentはあなたのエントリーコンポーネントです。 ' router-outlet>を持たないため、あなたのルータはあなたの' HomeComponent'をロードする場所を知らない –
LLai
ありがとう@guramidev。あなたが答えを入れたら、それにチェックをつけます。 –