Skip to content

Commit 4b451d8

Browse files
authored
Allow empty hash for cleaner default URLs on the home screen (#349)
This makes sure we don't need the #home hash for the default page URL.
1 parent 64a5e7c commit 4b451d8

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

resources/main.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ section {
287287
border-radius: 20px;
288288
}
289289

290-
section:target {
290+
section:target,
291+
body:not(body:has(section:target)) #home {
291292
display: block;
292293
}
293294

resources/main.mjs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,20 +331,32 @@ class MainBenchmarkClient {
331331

332332
_showSection(hash) {
333333
if (this._isRunning) {
334-
window.location.hash = "#running";
334+
this._setLocationHash("#running");
335335
return;
336336
} else if (this._hasResults) {
337337
if (hash !== "#summary" && hash !== "#details") {
338-
window.location.hash = "#summary";
338+
this._setLocationHash("#summary");
339339
return;
340340
}
341341
} else {
342-
if (hash !== "#home" && hash !== "#about") {
343-
window.location.hash = "#home";
342+
if (hash !== "" && hash !== "#home" && hash !== "#about") {
343+
this._setLocationHash("#home");
344344
return;
345345
}
346346
}
347-
window.location.hash = hash || "#home";
347+
this._setLocationHash(hash);
348+
}
349+
350+
_setLocationHash(hash) {
351+
if (hash === "#home" || hash === "")
352+
this._removeLocationHash();
353+
else
354+
window.location.hash = hash;
355+
}
356+
357+
_removeLocationHash() {
358+
const location = window.location;
359+
window.history.pushState("", document.title, location.pathname + location.search);
348360
}
349361
}
350362

0 commit comments

Comments
 (0)