简体   繁体   English

Angular forRoot()

[英]Angular forRoot()

I have a forRoot method, however when I go to the designated address I don't get what the component has inside.我有一个forRoot方法,但是当我 go 到指定地址时,我没有得到组件内部的内容。 Why?为什么? How does forRoot work? forRoot是如何工作的?

It's my app.module.ts:这是我的 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 { }

I think you can find out what RouterModule.forRoot does on the Angular website我想你可以在 Angular网站上找到RouterModule.forRoot的作用

or if you are interested in the code you can see that on the Angular Git repo .或者,如果您对代码感兴趣,您可以在Angular Git repo上看到该代码。

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

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