routerLink not working in Angular 6

白昼怎懂夜的黑 提交于 2020-01-02 03:20:17

问题


I'm learning 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

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

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

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

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


回答1:


You have not imported RouterModule in ContactsModule.

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

@NgModule({
   imports: [
     RouterModule
   ],



回答2:


Add this in your contacts.module.ts

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

 @NgModule({
    imports: [
       RouterModule
     ],



回答3:


You have forgotten to import RouterModule in your contacts Module

I've did that in your stackblitz and it worked.



来源:https://stackoverflow.com/questions/51859992/routerlink-not-working-in-angular-6

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!