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