Skip to content

Commit 413eeee

Browse files
committed
Remove hash from URL after loading
1 parent bfde86b commit 413eeee

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

src/App.svelte

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,25 @@
6464
return p;
6565
}
6666
67+
let ignoreHashChange = false;
6768
async function hashChange() {
68-
if (window.location.hash.startsWith('#project=')) {
69+
const hash = window.location.hash;
70+
if (hash.length > 0) {
71+
ignoreHashChange = true;
72+
window.history.replaceState(
73+
undefined,
74+
undefined,
75+
window.location.pathname + window.location.search,
76+
);
77+
ignoreHashChange = false;
78+
}
79+
if (ignoreHashChange) {
80+
return;
81+
}
82+
83+
if (hash.startsWith('#project=')) {
6984
try {
70-
const json = decodeURIComponent(
71-
window.location.hash.substring(9),
72-
);
85+
const json = decodeURIComponent(hash.substring(9));
7386
openProject(newSession(), {
7487
...JSON.parse(json),
7588
timestamp: Date.now(),
@@ -80,11 +93,9 @@
8093
}
8194
}
8295
83-
if (window.location.hash.startsWith('#code=')) {
96+
if (hash.startsWith('#code=')) {
8497
try {
85-
const contents = decodeURIComponent(
86-
window.location.hash.substring(6),
87-
);
98+
const contents = decodeURIComponent(hash.substring(6));
8899
openProject(newSession(), {
89100
files: [
90101
{
@@ -101,11 +112,9 @@
101112
}
102113
}
103114
104-
if (window.location.hash.startsWith('#url=')) {
115+
if (hash.startsWith('#url=')) {
105116
try {
106-
const url = decodeURIComponent(
107-
window.location.hash.substring(5),
108-
);
117+
const url = decodeURIComponent(hash.substring(5));
109118
openProject(newSession(), await loadFromUrl(url));
110119
return;
111120
} catch (e) {

0 commit comments

Comments
 (0)