Skip to content

Retaining component state on page change #2697

Closed Answered by gbj
john- asked this question in Q&A
Discussion options

You must be logged in to vote

So this is working as designed and the way any reasonable framework would work: when you navigate away from the page, it releases any memory allocated on that page (rather than just leaking memory as you navigate page to page).

A good way to share state between different pages would be to "hoist" it up into a higher scope, and then share it with the child.

In your example, you would pull the count signal up into the scope of the App component instead of the page it's on, so that it is created once during the life of the app: then pass it as a prop or using context.

Note that for the Route view prop, view can be any function including a closure, so you can do something like view=move || vi…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@john-
Comment options

Answer selected by john-
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants