7

I know lots have already asked this question but none of them gave clear answer. I just want to store the state of component when it navigates to another and then come back to previous one. I know we can save the data in service and then fetch the dats back to component. But, I think this is easy but not the better solution when the component is too complex. I read some router reuse things but non of them work in angular 2.

Kai
  • 2,529
  • 1
  • 15
  • 24
Sudhir Roy
  • 256
  • 2
  • 3
  • 11

1 Answers1

7

There are several options:

1) Use a service. This is actually one of the best ways if the data is complex. I have a simple example here: https://blogs.msmvps.com/deborahk/build-a-simple-angular-service-to-share-data/

2) Routing parameters. You can specify required, optional, or query parameters. See this for more information: Sending data with route.navigate in Angular 2

If you are looking for information on the router reuse strategies, you can find some information here: https://medium.com/@juliapassynkova/angular-2-component-reuse-strategy-9f3ddfab23f5

DeborahK
  • 57,520
  • 12
  • 104
  • 129
  • Asked this question around July 2017 and now in 2018, what I understand is simply save the data in service file and again use that data when you comes back on that page. Hence other answer still didn't come from @angular team. – Sudhir Roy Jan 08 '18 at 20:51
  • 1
    I don't believe that the Angular team monitors these forums. Stackoverflow is community supported. We are all just volunteers here. – DeborahK Jan 08 '18 at 22:19
  • 1
    I updated my answer above to provide information on router reuse as well if that is what you are really looking for? – DeborahK Jan 08 '18 at 22:21
  • this is why I don't want to use Ionic4 (angular based routing) and keep Ionic3 (it keeps the component state automaticly!) – Ari Waisberg Nov 29 '19 at 12:22