首页 文章

为什么RoutingModule无法在我的角应用程序中运行?

提问于
浏览
0

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

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

但我有一个错误

“未捕获错误:模板解析错误:无法绑定到'routerLink',因为它不是'h4'的已知属性 . (”class =“col-3”>] routerLink =“/ profile / {} / public“> {}”):ng:///CastraModule/CastrasComponent.html@18:85 at syntaxError(compiler.js:215)at TemplateParser.push ../ node_modules /位于JitCompiler.push的@ angular / compiler / fesm5 / compiler.js.TemplateParser.parse(compiler.js:14687)../ node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._parseTemplate(compiler.js:22687 )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):22007 atit.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 { }

我的TestRoutingModule

(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模块中导入的,那么问题是什么?

2 回答

  • 1

    你可能需要?把它包在里面 <a> and </a>

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

    EDIT

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

  • 0

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

相关问题