mirror of
https://github.com/vector-im/element-call.git
synced 2024-11-30 00:50:48 +08:00
26 lines
549 B
JavaScript
26 lines
549 B
JavaScript
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]);
|
|
}
|