S
SolidJS12mo ago
ai6

How to prevent component from unmounting on navigation?

[SOLVED] I need a specific component to preserve its state as the user is navigating. Currently, the component unmounts and remounts every time the route changes, as you can see in this example. How can I prevent this?
1 Reply
ai6
ai612mo ago
From this article:
In Solid, all rendering and DOM interaction is a side effect of the reactive system. Even basics like mount/unmount are not based on DOM action. A reactive context is "mounted" when it has finished settling for the first time, and "unmounted" when its parent context is re-evaluated or removed.
Since the <Routes> component re-evaluates on any route change, that means all of its children will be unmounted. So the solution is to just keep the component outside of <Routes>! Not sure what the implications or downsides of this are, but everything seems fine for now.
DEV Community
5 Places SolidJS is not the Best
In this article, I wish to finally address the question "What is Solid not as good at?" The list migh...