From 2e2c6765b5b51dff9297211372189037d85a8d58 Mon Sep 17 00:00:00 2001 From: tophf Date: Mon, 31 Jan 2022 17:27:58 +0300 Subject: [PATCH] keep router buffer on tab reload (#1393) --- js/router.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/js/router.js b/js/router.js index 6c6d6f19..fa3121f9 100644 --- a/js/router.js +++ b/js/router.js @@ -3,13 +3,19 @@ 'use strict'; const router = { - buffer: [], + buffer: (history.state || {}).buffer || [], watchers: [], getSearch(key) { return new URLSearchParams(location.search).get(key); }, + push(url) { + const state = history.state || {}; + state.buffer = router.buffer; + history.pushState(state, null, url); + }, + update(replace) { const {buffer} = router; if (!buffer.length) { @@ -53,7 +59,7 @@ const router = { if (!hash) { hash = ' '; } - history.pushState(history.state, null, hash); + router.push(hash); router.update(); }, @@ -83,7 +89,7 @@ window.on('popstate', () => router.update()); window.on('hashchange', () => router.update()); msg.on(e => { if (e.method === 'pushState' && e.url !== location.href) { - history.pushState(history.state, null, e.url); + router.push(e.url); router.update(); return true; }