[英]How to fix this error in Angular routing?
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import {HomeComponent} from "./home/home.component";
import {SettingsComponent} from "./settings/settings.component";
const routes: Routes = [
{path: 'home', component: HomeComponent},
{path: 'settings', component: SettingsComponent},
{path: '', redirectTo: 'home', pathMatch: 'full'
},
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule {
}
export const routingComponents = [HomeComponent, SettingsComponent]
它工作得很好,但是當我將private homeservice: HomeService
添加到我的home.component.ts
的構造函數中時,我的應用程序開始在app.component.html
中向我顯示一個白頁,我什么也做不了。 如何解決此路由問題?
將路由器插座添加到您的 app.component.html
<router-outlet></router-outlet>
我相信您沒有在模塊中添加 HomeService。 您可以將其添加到模塊的 Provider 部分。 所以我認為它解決了你的問題
providers: [ HomeService ]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.