Skip to content

Commit 635dea0

Browse files
committed
make it closer to what nextjs was doing
1 parent 756a6e0 commit 635dea0

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

reflex/.templates/web/utils/state.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,17 @@ export const useEventLoop = (
10221022

10231023
// Route after the initial page hydration
10241024
useEffect(() => {
1025+
// This will run when the location changes
1026+
if (
1027+
location.pathname + location.search ===
1028+
prevLocationRef.current.pathname + prevLocationRef.current.search
1029+
) {
1030+
if (location.hash) {
1031+
// If the hash is the same, we don't need to do anything.
1032+
return;
1033+
}
1034+
}
1035+
10251036
// Equivalent to routeChangeStart - runs when navigation begins
10261037
const main_state_dispatch = dispatch["reflex___state____state"];
10271038
if (main_state_dispatch !== undefined) {
@@ -1030,6 +1041,9 @@ export const useEventLoop = (
10301041

10311042
// Equivalent to routeChangeComplete - runs after navigation completes
10321043
addEvents(onLoadInternalEvent());
1044+
1045+
// Update the ref
1046+
prevLocationRef.current = location;
10331047
}, [location, dispatch, onLoadInternalEvent, addEvents]);
10341048

10351049
return [addEvents, connectErrors];

0 commit comments

Comments
 (0)