routerLink 在 Angular 6 中不起作用 [英] routerLink not working in Angular 6
本文介绍了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
],
这篇关于routerLink 在 Angular 6 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文