簡體   English   中英

導航到使用相同組件的另一條路線時,組件的角度檢索狀態

[英]Angular Retrieve state of a component when navigating to another route that uses the same component

我有兩個不同的路由/a/b使用相同的組件。 /a導航到/b ,我希望能夠檢索/a中使用的組件實例的狀態以在/b重用它。

我在這里https://github.com/angular/angular/issues/12446讀到,使用Angular“自定義路由重用策略”已經或將有可能。 我想知道是否可以使用當前的RouteReuseStrategy 因為在返回相同的URL時重用一個組件似乎很容易,但是在使用相同的組件訪問不同的URL時卻不容易。

我不確定您的實時用例,但是可以使用RouteReuseStrategy重用UI或Component狀態。 您必須為路由生成一個通用的唯一密鑰,並在離開路由時存儲該狀態。 當路由具有相同密鑰的路由返回時,可以重新使用存儲狀態。

在此https://plnkr.co/edit/wFPn16?p=preview

  Visited component state reused when you visit to different route. For example view and edit item with id 12345. then check the view and> edit details for id 12346. View and edit component show the details related 12345. 

HTH

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM