[英]Angular 2/4+ Shared Module: To forRoot() or not to forRoot()
[英]Angular forRoot()
我有一個forRoot
方法,但是當我 go 到指定地址時,我沒有得到組件內部的內容。 為什么? forRoot
是如何工作的?
這是我的 app.module.ts:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
import { HomeComponent } from './components/home/home.component';
import { RegisterComponent } from './components/register/register.component';
@NgModule({
declarations: [
AppComponent,
HomeComponent,
RegisterComponent,
],
imports: [
BrowserModule.withServerTransition({ appId: 'ng-cli-universal' }),
HttpClientModule,
FormsModule,
/*RouterModule.forRoot([
{ path: '', component: HomeComponent, pathMatch: 'full' },
{ path: 'counter', component: CounterComponent },
{ path: 'fetch-data', component: FetchDataComponent },*/
RouterModule.forRoot([
{ path: 'test', component: HomeComponent },
{ path: 'account/register', component: RegisterComponent }
], { relativeLinkResolution: 'legacy' })
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
我想你可以在 Angular網站上找到RouterModule.forRoot
的作用
或者,如果您對代碼感興趣,您可以在Angular Git repo上看到該代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.