From 483b4798909ec91c405ee7eb1d6de28d416d5715 Mon Sep 17 00:00:00 2001 From: Andrea Date: Tue, 26 Apr 2022 20:53:15 +0200 Subject: [PATCH] [bug] somehow "=" starts getting added to hashes, add some quick handling --- plugins/hash.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/plugins/hash.js b/plugins/hash.js index 3823632e..3eab8f39 100644 --- a/plugins/hash.js +++ b/plugins/hash.js @@ -1,12 +1,15 @@ export default { methods: { + getHash() { + if (!process.client) { return null; } + + return decodeURIComponent(window.location.hash.substr(1).replace(/=$/, '')); + }, handleHash(namespace, callback, checkAnchor = true) { - if (!process.client) { - return; - } + if (!process.client) { return; } const doHandle = () => { - const anchor = decodeURIComponent(window.location.hash.substr(1)); + const anchor = this.getHash(); const $anchor = document.getElementById(anchor); if (checkAnchor && $anchor) { $anchor.scrollIntoView(); @@ -25,15 +28,17 @@ export default { }, 500); }, setHash(namespace, value) { - if (!process.client) { - return; - } + if (!process.client) { return; } + const current = this.getHash(); + const fullValue = namespace ? namespace + '/' + value : value + + if (fullValue === current) { return; } history.pushState( '', document.title, window.location.pathname + window.location.search - + (value ? '#' + (namespace ? namespace + '/' + value : value) : '') + + (value ? '#' + fullValue : '') ); }, }