routerLink在Angular 6中不起作用

问题描述:

我正在学习Angular 6.

我已将应用程序结构设计为具有以下结构的层次结构形式.

I have designed my application structure in hierarchy form with following structure.

my_app
 |- src
    |- app
       |- layout
          |- admin-layout
             |- admin-layout.module.ts
             |- admin-layout.routing.ts
             |- admin-layout.component.html
       |- contacts
          |- contact-list
             |- contact-list.component.ts
             |- contact-list.component.html
          |- contacts.module.ts
       |- transaction
          |- amount-given
             |- amount-given-list
                |- amount-given-list.component.ts
                |- amount-given-list.component.html
             |- amount-given.module.ts
             |- amount-given.routing.ts
             |- amount-given.service.ts
          |- transaction.module.ts
          |- transaction.routing.ts
       |- app.module.ts
       |- app.component.html
       |- app-routing.module.ts

可在此处找到源代码和演示图: https://stackblitz.com/edit/angular-wcglvr

The source code and demo illustration can be found here: https://stackblitz.com/edit/angular-wcglvr

<a routerLink="/dashboard">Dashboard</a>

/transaction/amount-given/amount-given-list/上工作,但在/contacts/contact-list上工作.

is working from /transaction/amount-given/amount-given-list/ but not from /contacts/contact-list.

由于源代码非常长且具有层次结构,因此我在 stackblitz 上添加了演示示例.

Since source code is quite long and hierarchical, I have added demo illustration on stackblitz.

您尚未在ContactsModule中导入RouterModule.

import {RouterModule} from '@angular/router';

@NgModule({
   imports: [
     RouterModule
   ],