Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度5路由问题(重定向回主页)_Angular_Routing_Routes - Fatal编程技术网

Angular 角度5路由问题(重定向回主页)

Angular 角度5路由问题(重定向回主页),angular,routing,routes,Angular,Routing,Routes,我在Angular 5项目中遇到了一个问题。我正在尝试从我的LocationDetailComponent导航到ClientListComponent。我在LocationDetailComponent中的HTML代码中包含以下内容: <a href class="cp" (click)="seeClients(ap.name);"> {{ ap.details.apclientcount }} </a></td> seeClients(ap): voi

我在Angular 5项目中遇到了一个问题。我正在尝试从我的LocationDetailComponent导航到ClientListComponent。我在LocationDetailComponent中的HTML代码中包含以下内容:

<a href class="cp" 
(click)="seeClients(ap.name);"> {{ ap.details.apclientcount }} 
</a></td>
seeClients(ap): void {
    console.log(ap);
    this.router.navigate(['clients/' + ap]);
}
路线:

const routes: Routes = [
  {path: '', redirectTo: '/', pathMatch: 'full'},
  {path: '', component: HomeComponent},
  {path: 'locations', component: LocationListComponent},
  {path: 'location/:id', component: LocationDetailComponent},          
  {path: 'clients/:id', component: ClientListComponent},
  {path: 'client/:id', component: ClientDetailComponent},
  {path: '404', component: Error404Component},
  // otherwise redirect to 404
  {path: '**', redirectTo: '/404'}
];
当我从LocationListComponent到LocationDetailComponent执行此操作时,效果很好,但当我转到ClientListComponent时,我会看到该组件一两秒钟,然后它会重定向回HomeComponent。我不明白为什么?使用RouterModule的{enableTracing:true}选项,我在URL中看到:

NavigationEnd{id:4,url:/clients/W0233-01-008,urlAfterRedirects:/clients/W0233-01-008}

这是正确的,并加载了正确的组件-但随后突然出现导航到,并获得路径“/”


想知道为什么吗?

这是通过不使用创建到其他组件的链接来解决的-使用worked。仍然很好奇,为什么当您使用href提供锚定标记时,浏览器会自动将您重定向到您在href中提供的链接。 如果您使用href使游标看起来像指针,请使用cursor:pointer添加css类