简体   繁体   中英

Keep component state using RouteReuseStrategy

I have a simple app , with two routes:

/dashboard => DashboardComponent
/profile   => ProfileComponent

The DashboardComponent has a "Load" button, which can toggle the message " I am loading... ". Whenever I navigate out of this component, I would like to keep the state of it (still show the message "I am loading..." if the Load button has been previously pressed).

How can I achieve that? (the ActivatedRouteSnapshot.routeConfig is always null, so I don't know the route I am navigation to)

Please take into consideration, that I am only interested in using the RouteReuseStrategy and not keeping the state inside a parent component.

It is not necessary to use RouteReuseStrategy. You could keep the state in a service then use this data when user navigate back to the page. Refer to demo

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM