From 30a62e6378914808ba1c640be2e5bd7758942433 Mon Sep 17 00:00:00 2001 From: knotteye Date: Sat, 17 Oct 2020 16:02:50 -0500 Subject: [PATCH] Handle back button when the user navigates to one of our own history events --- site/index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/site/index.js b/site/index.js index ff2bc7f..c52c1c2 100644 --- a/site/index.js +++ b/site/index.js @@ -1,6 +1,7 @@ -async function render(path){ +async function render(path, s){ var context = await getContext(); - history.pushState({}, context.sitename, location.protocol+'//'+location.host+path); + if(!s) + history.pushState({}, context.sitename, location.protocol+'//'+location.host+path); switch(path){ //nothing but context case (path.match(/^\/about\/?$/) || {}).input: @@ -115,6 +116,10 @@ async function render(path){ } } +window.addEventListener('popstate', (event) => { + render(document.location.pathname, true); +}); + async function getContext(){ var info = JSON.parse(await makeRequest('GET', '/api/instance/info')); info.sitename = info.name;