I have two different routes /a
and /b
using the same component. When navigating from /a
to /b
, I'd like to be able to retrieve the state of the component instance used in /a
to reuse it in /b
.
I read here https://github.com/angular/angular/issues/12446 that it is or will be possible using Angular "custom route reuse strategies". I am wondering if it's possible using the current RouteReuseStrategy ? Because it seems to be easy to reuse a component when going back to the same url but not when going to a different url using the same component.
I am not sure about your real time use case but you can use RouteReuseStrategy reuse the UI or Component state. You have to generate a common unique key for both route and store that state when you leave the route. Stored state can be re-used when route back with routes which has same key.
In this 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.