angular - Angular 6 - 可重用组件 - 路线导航
问题描述
目前,我正在为三个不同的组件呈现完全相同的表结构,该表结构位于共享文件夹中。问题是,我在桌子上有后退按钮,每当我点击它时,它应该从它的实际来源导航回组件视图。
假设:
componentA -> commonTblCompoent - click Back - go to componentA
componentB -> commonTblCompoent - click Back - go to componentB
componentC -> commonTblCompoent - click Back - go to componentC
现在导航只发生在组件A上。如何巧妙地更改路由配置。
组件A.ts
gotoCommonTbl {
this.router.navigate(['cmnTable/commonTbl']);
}
组件B.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
}
有人可以告诉我如何重写和解决这个问题吗?如果可能,请分享任何示例工作演示
谢谢大家
解决方案
您可以考虑使用Location
该类CommonTbl
并将用户发送回他们来自的地方:
import { Location } from '@angular/common';
constructor(private location: Location) { }
gotocurrentComponent() {
this.location.back();
}
推荐阅读
- javascript - 如何检查对象中值的类型
- laravel - Livewire 上的多个输入值
- javascript - POST 500(内部服务器错误)无法在节点服务器上使用 react js 发布表单数据
- javascript - 将 js-object(在字符串中)转换为 JSON
- typescript - Visual Studio 2019 typescript:Intellisense 报告非错误的错误
- kubernetes - k3s 将 http 重定向到 https
- c++ - sched_yield 标记为顶级热点
- html - 值的差异,显示正负
- javascript - 从JavaScript中的原始数组中删除另一个数组中存在的项目?
- unit-testing - 在 Clojure 中使用 Lacinia-Pedestal 进行端点单元测试