Skip to content

Commit ea2bc5f

Browse files
authored
fix: replace state (#278)
1 parent cb3004c commit ea2bc5f

File tree

1 file changed

+5
-20
lines changed

1 file changed

+5
-20
lines changed

src/app.tsx

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import Map from "./components/map";
77
import Overlay from "./components/overlay";
88
import { ErrorBoundaryAlert } from "./components/ui/error-alert";
99
import { useStore } from "./store";
10-
import { getCurrentHref } from "./utils/href";
1110
import { uploadFile } from "./utils/upload";
1211

1312
function MapFallback({ error }: { error: unknown }) {
@@ -36,32 +35,18 @@ export default function App() {
3635
const { db } = useDuckDb();
3736

3837
useEffect(() => {
39-
if (href) {
40-
history.pushState(null, "", "?href=" + href);
41-
document.title = "stac-map | " + href;
42-
} else {
43-
history.pushState(null, "", location.pathname);
44-
document.title = "stac-map";
45-
}
38+
if (href && new URLSearchParams(location.search).get("href") !== href)
39+
history.replaceState(null, "", "?href=" + href);
40+
else history.replaceState(null, "", null);
4641
}, [href]);
4742

4843
useEffect(() => {
4944
function handlePopState() {
50-
setHref(getCurrentHref() ?? "");
45+
setHref(new URLSearchParams(location.search).get("href"));
5146
}
5247
window.addEventListener("popstate", handlePopState);
5348

54-
if (getCurrentHref()) {
55-
try {
56-
new URL(getCurrentHref());
57-
} catch {
58-
history.pushState(null, "", location.pathname);
59-
}
60-
}
61-
62-
return () => {
63-
window.removeEventListener("popstate", handlePopState);
64-
};
49+
return () => window.removeEventListener("popstate", handlePopState);
6550
}, [setHref]);
6651

6752
useEffect(() => {

0 commit comments

Comments
 (0)