keep router buffer on tab reload (#1393)
This commit is contained in:
parent
b2bc18c3d5
commit
2e2c6765b5
12
js/router.js
12
js/router.js
|
@ -3,13 +3,19 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const router = {
|
const router = {
|
||||||
buffer: [],
|
buffer: (history.state || {}).buffer || [],
|
||||||
watchers: [],
|
watchers: [],
|
||||||
|
|
||||||
getSearch(key) {
|
getSearch(key) {
|
||||||
return new URLSearchParams(location.search).get(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) {
|
update(replace) {
|
||||||
const {buffer} = router;
|
const {buffer} = router;
|
||||||
if (!buffer.length) {
|
if (!buffer.length) {
|
||||||
|
@ -53,7 +59,7 @@ const router = {
|
||||||
if (!hash) {
|
if (!hash) {
|
||||||
hash = ' ';
|
hash = ' ';
|
||||||
}
|
}
|
||||||
history.pushState(history.state, null, hash);
|
router.push(hash);
|
||||||
router.update();
|
router.update();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -83,7 +89,7 @@ window.on('popstate', () => router.update());
|
||||||
window.on('hashchange', () => router.update());
|
window.on('hashchange', () => router.update());
|
||||||
msg.on(e => {
|
msg.on(e => {
|
||||||
if (e.method === 'pushState' && e.url !== location.href) {
|
if (e.method === 'pushState' && e.url !== location.href) {
|
||||||
history.pushState(history.state, null, e.url);
|
router.push(e.url);
|
||||||
router.update();
|
router.update();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user