为什么 RoutingModule 在我的 angular 应用程序中不起作用?

why is RoutingModule not working in my angular app?

编辑:请注意,在尝试将我的应用程序模块拆分为用于延迟加载的功能模块之前,一切正常

所以我正在尝试将我的应用程序模块拆分为其他功能模块,以便我可以在我的 angular 应用程序中使用延迟加载,

但我遇到了错误

"Uncaught Error: Template parse errors: Can't bind to 'routerLink' since it isn't a known property of 'h4'. ("class="col-3"> ]routerLink="/profile/{{castra.id}}/public"> {{castra.name}} "): ng:///CastraModule/CastrasComponent.html@18:85 at syntaxError (compiler.js:215) at TemplateParser.push../node_modules/@angular/compiler/fesm5/compiler.js.TemplateParser.parse (compiler.js:14687) at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._parseTemplate (compiler.js:22687) at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileTemplate (compiler.js:22674) at compiler.js:22617 at Set.forEach () at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileComponents (compiler.js:22617) at compiler.js:22527 at Object.then (compiler.js:206) at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileModuleAndComponents (compiler.js:22526)"

这是我的功能模块

(Imports)

@NgModule({
declarations: [
CastrasComponent,
ProfileComponent,
PublicComponent,
MenuComponent,
ReservationComponent
],
imports: [
CommonModule,
TestRoutingModule
]
})
export class CastraModule { }

我的测试路由模块

(Imports)
const testRoutes: Routes = [
{path: 'test', component: TestComponent},
{
path: 'profile/:id', component: ProfileComponent,
children: [
  {path: '', redirectTo: '/profile/:id/public', pathMatch: 'full'},
  {path: 'public', component: PublicComponent},
  {path: 'menu', component: MenuComponent},
  {path: 'reservation', component: ReservationComponent},
  ]
 }
]

@NgModule({
imports: [
RouterModule.forChild(TestRoutes)
],
exports: [RouterModule]
})
export class TestRoutingModule { }

App模块中导入了Test Module,请问是什么问题?

您可能需要?把它包在 <a> and </a>

里面
<h4><a routerLink="menu">Part1</a></h4>

编辑

您需要将 RouterModule 添加到每个使用 RouterOutlet 或 routerLink 等路由器指令的模块的 imports: []

您可以尝试使用 RouterModule.forRoot(TestRoutes) 而不是 RouterModule.forChild(TestRoutes) 它在我的路由器文件中有效