Angular 角度6-可重用组件-路线导航

Angular 角度6-可重用组件-路线导航,angular,typescript,Angular,Typescript,目前,我正在为三个不同的组件呈现与共享文件夹中完全相同的表结构。问题是,我在表上有一个后退按钮,每当我点击它时,它应该从它的实际来源导航回组件视图 假设: componentA -> commonTblCompoent - click Back - go to componentA componentB -> commonTblCompoent - click Back - go to componentB componentC -> commonTblCompoent -

目前,我正在为三个不同的组件呈现与共享文件夹中完全相同的表结构。问题是,我在表上有一个后退按钮,每当我点击它时,它应该从它的实际来源导航回组件视图

假设:

componentA -> commonTblCompoent - click Back - go to componentA 
componentB -> commonTblCompoent - click Back - go to componentB 
componentC -> commonTblCompoent - click Back - go to componentC
现在导航只发生在componentA上。如何灵活地更改路由配置

组件ts

gotoCommonTbl {
    this.router.navigate(['cmnTable/commonTbl']);
}
gotoCommonTbl {
    this.router.navigate(['cmnTable/commonTbl']);
}
gotocurrentComponent() {
//this.router.navigate(['componentA/comp-A']);

// this is supposed to be changed for proper navigation
}
组件b.ts

gotoCommonTbl {
    this.router.navigate(['cmnTable/commonTbl']);
}
gotoCommonTbl {
    this.router.navigate(['cmnTable/commonTbl']);
}
gotocurrentComponent() {
//this.router.navigate(['componentA/comp-A']);

// this is supposed to be changed for proper navigation
}
commonTbl.ts

gotoCommonTbl {
    this.router.navigate(['cmnTable/commonTbl']);
}
gotoCommonTbl {
    this.router.navigate(['cmnTable/commonTbl']);
}
gotocurrentComponent() {
//this.router.navigate(['componentA/comp-A']);

// this is supposed to be changed for proper navigation
}
有人能告诉我如何重写和修复这个问题吗?如果可能,请分享任何工作演示示例


<>谢谢所有的

你可以考虑使用<代码>位置<代码>类在<代码> CONBUBL中,并将用户发送回他们来自何处:

import { Location } from '@angular/common';

constructor(private location: Location) { }

gotocurrentComponent() {
  this.location.back();
}