solid-router
solid-router copied to clipboard
Feature request: persist route (don't unmount when navigate out)
Describe the bug
Not a bug, but no templates for feature requests.
I want to be able to avoid rerendering a previously visited route and the route should keep all the internal state.
"persist?: boolean" prop would be nice Syntax proposal:
<Routes><Route path="/" persist element={...} /> </Routes>
The way I accomplish it right now:
<Routes>
<Route path="/" element={<Home />} />
<Route path="/stack" />
...
</Routes>
<PersistRoute path="/stack" component={StackTest} />
export const PersistRoute = (p: { path: string; component: FC }) => {
const match = useMatch(() => p.path)
let dispose: () => void | undefined
const render = once(() => {
return createRoot(_dispose => {
dispose = _dispose
return <p.component />
})
})
onCleanup(() => dispose?.())
return <Show when={match()}>{render()}</Show>
}
Your Example Website or App
https://github.com/solidjs/solid-router
Steps to Reproduce the Bug or Issue
None
Expected behavior
When <Route> has "persist" prop it should mount the component on first visit and not cleanup on navigate out
Screenshots or Videos
No response
Platform
all
Additional context
No response