【问题标题】:Angular 6 - Reusable component - Route navigationAngular 6 - 可重用组件 - 路线导航
【发布时间】:2019-05-20 17:39:46
【问题描述】:

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

假设:

componentA -> commonTblCompoent - click Back - go to componentA 
componentB -> commonTblCompoent - click Back - go to componentB 
componentC -> commonTblCompoent - click Back - go to componentC

现在导航只发生在组件 A 上。如何巧妙地改变路由配置。

compoentA.ts

gotoCommonTbl {
    this.router.navigate(['cmnTable/commonTbl']);
}

compoentB.ts

gotoCommonTbl {
    this.router.navigate(['cmnTable/commonTbl']);
}

commonTbl.ts

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

// this is supposed to be changed for proper navigation
}

谁能告诉我如何重写和解决这个问题?如果可能,请分享任何示例工作演示

谢谢大家

【问题讨论】:

    标签: angular typescript


    【解决方案1】:

    您可以考虑在CommonTbl 中使用Location 类并将用户送回他们来自的地方:

    import { Location } from '@angular/common';
    
    constructor(private location: Location) { }
    
    gotocurrentComponent() {
      this.location.back();
    }
    

    https://stackblitz.com/edit/angular-yajvoj

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-22
      • 1970-01-01
      • 2019-05-02
      • 1970-01-01
      • 1970-01-01
      • 2020-08-24
      • 2019-05-17
      • 1970-01-01
      相关资源
      最近更新 更多