diff --git a/web/src/app/js/app.js b/web/src/app/js/app.js index 9cea948..d8cfec8 100644 --- a/web/src/app/js/app.js +++ b/web/src/app/js/app.js @@ -418,12 +418,18 @@ window.onload = function(e) { window.onhashchange(); } +var prevHash = null; window.onhashchange = function(e) { - var path = window.location.hash.substring(1).trim(); + try { + window.prevHash = new URL(e.oldURL) + .hash.substr(1).trim(); + } catch (e) { window.prevHash = null } + var path = window.location.hash.substr(1).trim(); var args = path.split('/'); if (args.length > 0 && args[0].trim() === '') args = []; + window.lastHash = path; for (var i = 0; i < app.hashHandlers.length; i++) { const cfg = app.hashHandlers[i]; if (cfg.exact !== undefined && diff --git a/web/src/app/js/base.js b/web/src/app/js/base.js index 768c4b5..fe75228 100644 --- a/web/src/app/js/base.js +++ b/web/src/app/js/base.js @@ -142,6 +142,13 @@ function loadScript(id, file, cback) { document.body.appendChild(script); } +function hashredir(tohash, fallback) { + fallback = fallback || ''; + if (tohash === undefined || tohash === null) + tohash = fallback; + window.location.href = `#${tohash}`; +} + function printstack() { console.error(new Error().stack) } function uuidv4() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { diff --git a/web/src/app/js/pages/home.js b/web/src/app/js/pages/home.js index 8bb9f03..a07d69a 100644 --- a/web/src/app/js/pages/home.js +++ b/web/src/app/js/pages/home.js @@ -18,10 +18,10 @@ app.pages.home = { setTimeout(function() { document.getElementById('app-container').innerHTML = ''; if (app.template.isLoaded('quiz.index')) - window.location.href = `#quiz/${id}` + hashredir(`quiz/${id}`); }, 80); if (!app.template.isLoaded('quiz.index')) - window.location.href = `#quiz/${id}`; + hashredir(`quiz/${id}`); }, paint: function(section, json) { json = json || app.pages.home.data[section]; diff --git a/web/src/app/js/pages/meet.js b/web/src/app/js/pages/meet.js index e863295..3d1abef 100644 --- a/web/src/app/js/pages/meet.js +++ b/web/src/app/js/pages/meet.js @@ -204,7 +204,7 @@ app.pages.meet = { }, }, exit: function() { - window.location.href = '#'; + hashredir(window.prevHash); app.overlay.hideAll(); }, carousel: {