From 22748d0e1841d7db0f5269e70cd034ed283aee72 Mon Sep 17 00:00:00 2001 From: eight Date: Sat, 1 Feb 2020 17:32:14 +0800 Subject: [PATCH] Fix: greedly pop the buffer --- js/router.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/js/router.js b/js/router.js index 5e353b82..b0dba56e 100644 --- a/js/router.js +++ b/js/router.js @@ -46,7 +46,6 @@ const router = (() => { */ if (buffer.length > 1) { if (!hash && !buffer[buffer.length - 2].includes('#') || buffer[buffer.length - 2].endsWith(hash)) { - buffer.pop(); history.back(); return; } @@ -63,10 +62,16 @@ const router = (() => { } function update(replace) { - if (!buffer.length || buffer[buffer.length - 1] !== location.href && !replace) { + if (!buffer.length) { buffer.push(location.href); - } else if (buffer.length && replace) { + } else if (buffer[buffer.length - 1] === location.href) { + return; + } else if (replace) { buffer[buffer.length - 1] = location.href; + } else if (buffer.length > 1 && buffer[buffer.length - 2] === location.href) { + buffer.pop(); + } else { + buffer.push(location.href); } for (const {options, callback} of watchers) { let state;