[英]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.