假設我有兩個途徑:如何路線之前得到的URL在角4
{ path: '/path1', component: component1 }
{ path: '/path2', component: component2 }
和我在「/路徑1」,並定位到「/路徑」。
所以我的問題是如何在組件2構造函數或代碼中的任何地方獲取路徑URL'/ path1'而無需通過任何服務使用解析或全局變量。
Component2.ts
export class Component2{
constructor(router: Router) {
router.events.subscribe((event) => {
// here I want to get route url '/path1' from component1
});
}
}
請讓我知道如果有人需要更多的澄清。
[如何確定angular2中的上一頁URL?](https://stackoverflow.com/questions/41038970/how-to-determine-previous-page-url-in-angular2) –
不可以將不會解決我的問題,因爲他們在導航到一些變量previousUrl:字符串之前保存路由url,但我想要的是從那裏導航獲取開始,即在其他組件導航結束,即在組件2. –