Use the solidjs router to jump to a new page, the original page will be destroyed, resulting in the use of history.back(); When you return, the original page is reloaded.
<Router>
<Routes>
<Route path="/Home" component={Home} />
<Route path="/User" component={User} />
</Routes>
</Router>
For example, switch from the home page to the User page, and then use history.back()
for the user page Go back, Home page refreshes again. This is not the effect I want. How can I keep the rendered page?
Router disposes a component when you navigate away from it. That is reasonable because so many parameters may have been been changed between two visits, otherwise the using previously rendered component would give you static pages.
If you don't want to re-render a component you can wrap it into a detached root using
createRoot
and dispose it manually when you done with it.A memoized component would also work but there is no way to trigger
onDispose
function on a memoized value.There is also a Github discussion on the issue which you can find at https://github.com/solidjs/solid/discussions/1054#discussioncomment-6711906. Currently I added the same answer but you may find some additions in the future.