Skip to content

Commit e820f4d

Browse files
committed
fix: state updates detection on back/forward event
1 parent 3cd2fef commit e820f4d

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

src/routing.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
createSignal,
88
on,
99
onCleanup,
10+
onMount,
1011
untrack,
1112
useContext,
1213
startTransition,
@@ -326,6 +327,10 @@ export function createRouterContext(
326327
}
327328
};
328329

330+
const handlePopState = () => setState(window.history.state);
331+
onMount(() => window.addEventListener("popstate", handlePopState));
332+
onCleanup(() => window.removeEventListener("popstate", handlePopState));
333+
329334
createRenderEffect(() => {
330335
const { value, state } = source();
331336
// Untrack this whole block so `start` doesn't cause Solid's Listener to be preserved

0 commit comments

Comments
 (0)