Add useLocationNavigation to fix navigation during browser media prompts

This commit is contained in:
Robert Long
2022-02-03 16:56:13 -08:00
parent a33d1364b6
commit 1d8cd8c3c8
3 changed files with 32 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
import { useEffect } from "react";
import { useHistory } from "react-router-dom";
export function useLocationNavigation(enabled = false) {
const history = useHistory();
useEffect(() => {
let unblock;
if (enabled) {
unblock = history.block((tx) => {
const url = new URL(tx.pathname, window.location.href);
url.search = tx.search;
url.hash = tx.hash;
window.location = url.href;
});
}
return () => {
if (unblock) {
unblock();
}
};
}, [history, enabled]);
}