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.

You have not imported RouterModule in ContactsModule.

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

@NgModule({
   imports: [
     RouterModule
   ],