Skip to content

Commit 9fe8b83

Browse files
committed
prevent update state when equals
1 parent f35cc69 commit 9fe8b83

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

router/index.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ export const ReloadContext = createContext(async (): Promise<void> => {});
9595
export function useRouteState<T extends {}>(key: string, initial: T) {
9696
return useReducer((_old: T, newvalue: T) => {
9797
const routeState = history.state ?? {};
98-
history.replaceState({ ...routeState, [key]: newvalue }, "");
98+
if (routeState[key] !== newvalue)
99+
history.replaceState({ ...routeState, [key]: newvalue }, "");
99100
return newvalue;
100101
}, (globalThis.history?.state?.[key] ?? initial) as unknown as T);
101102
}

0 commit comments

Comments
 (0)