伙计们,我创建了两个组件,注册了路径,在 html 中注册,但是当您在控制台中单击 localhost 链接时,我进入一个空白页面,控制台中没有错误。
应用程序路由.module.ts
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { HomeComponent } from './home/home.component';
import {RegistrationComponent} from './registration/registration.component';
const routes: Routes = [
{path: 'home', component: HomeComponent},
{path: '**', component: RegistrationComponent},
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { RegistrationComponent } from './registration/registration.component';
import { HomeComponent } from './home/home.component';
import { AppRoutingModule } from './app-routing.module';
import { HttpClientModule} from '@angular/common/http';
@NgModule({
declarations: [
AppComponent,
RegistrationComponent,
HomeComponent
],
imports: [
HttpClientModule,
BrowserModule,
AppRoutingModule,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
注册.component.html
<p>registration works!</p>
<router-outlet></router-outlet>