0

I'm new to Knockout JS and working on small single page application. I found some good examples and observed that even after page is saved and reloaded the data other copntrols are untouched. Their data is not lost.

Also I filled some details on Page1 and moved to Page2 and there I did some operations even saved the data and then came back to Page1, but still I found my data that I entered before moving to page2.

I wonder how does it maintain state? I din't find any article, or something similar. Can anyone give a hint how it works, and how can we maintain state?

Jeroen
  • 60,696
  • 40
  • 206
  • 339
sunil20000
  • 356
  • 3
  • 16
  • You said you are working on single page application, yet you have mentioned about page 1 and page 2. Can you explain breifly what your application is doing. Because it would be a news to me if knockout is indeed maintaining state. From all i know knockout is just client side. – Ramki Aug 27 '16 at 13:20
  • page1 and page2 are different links with different UI as I saw in some sample applications. – sunil20000 Sep 02 '16 at 09:28

1 Answers1

0

JavaScript applications in general typically loose their state once the user navigates away or closes the tab/window. KnockoutJS itself has nothing special to prevent state-loss from happening.

If you have a real SPA, then the user never "navigates away" from the SPA. It merely navigates within the SPA, which can be similar in user experience, but is totally different from a technical standpoint.

Even with a SPA, the user can navigate away from the SPA and come back to it later. Similar to a non-SPA application, the code will need some mechanism to preserve state across loads of the page or SPA.

Again, KO has nothing special for this. Your app needs code (or plugins) to handle this. Check out this generic advice on preserving state and/or have a go at building code for it yourself. If you have specific problems with your code, you can always get back to SO with a specific question.

Community
  • 1
  • 1
Jeroen
  • 60,696
  • 40
  • 206
  • 339