角 forRoot()

时间:2021-03-05 15:26:47

标签: angular routes

我有一个 forRoot 方法,但是当我去指定的地址时,我没有得到组件里面有什么。为什么? 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 { }

1 个答案:

答案 0 :(得分:0)

我想您可以了解 RouterModule.forRoot 在 Angular website 上的作用

或者如果您对代码感兴趣,您可以在 Angular Git repo 上看到它。

相关问题