首页 > 解决方案 > 无法导航到另一个组件 - Angular

问题描述

我有 3 个组件从第一个移动到第二个。但是从第二个开始,我无法浏览第三个组件。

Name仅显示超链接,但单击时没有任何反应。

这是第二个组件代码

<table>
<tr *ngFor="let lst of devices; let i = index" border="1">
  <td>{{lst.DeviceId}}</td>
  <td>{{lst.LastJobStatus}}</td>
  <td> <a routerLink="deviceapps">{{lst.Name}}</a> </td>
</tr>
</table>

App-routing.module.ts班级

const routes: Routes = [
  { path: 'devicelist/:id', component: DeviceListComponent } ,
  {path: 'deviceapps',component: DeviceAppsComponent}
];

第三部分代码

import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router, ParamMap } from '@angular/router';

@Component({
  selector: 'app-device-apps',
  templateUrl: './device-apps.component.html',
  styleUrls: ['./device-apps.component.css']
})
export class DeviceAppsComponent implements OnInit {

  constructor() { }

  ngOnInit() {
  }

}

标签: angularrouterlink

解决方案


看起来您在内部使用相对路径,因此请尝试编写绝对路由,例如:

<a [routerLink]="'/deviceapps'">{{lst.Name}}</a>

推荐阅读