From 8bbafd2f7d5f681e45b8dad6a226682f873aa6e5 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Wed, 13 Dec 2023 21:46:07 +0100 Subject: [PATCH] Better logic on the UI to parse the current URL fragment arguments. --- platypush/backend/http/webapp/src/utils/Url.vue | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/platypush/backend/http/webapp/src/utils/Url.vue b/platypush/backend/http/webapp/src/utils/Url.vue index 376e3a4f6..3f667437c 100644 --- a/platypush/backend/http/webapp/src/utils/Url.vue +++ b/platypush/backend/http/webapp/src/utils/Url.vue @@ -3,24 +3,28 @@ export default { name: "Url", methods: { parseUrlFragment() { - return window.location.href.replace(/.*#(\w+)[?;]?.*/, '$1') + return window.location.hash.replace(/^#/, '').replace(/\?.*/, '') }, getUrlArgs() { - return window.location.href - .replace(/.*#/, '') - .replace(/.*\?/, '') + const argsString = window.location.hash.split('?').slice(1) + if (!argsString.length) + return {} + + return argsString[0] .split(/[&;]/) .reduce((acc, obj) => { const tokens = obj.split('=') - acc[tokens[0]] = tokens[1] + if (tokens[0]?.length) + acc[tokens[0]] = tokens[1] return acc }, {}) }, setUrlArgs(args) { + args = {...this.getUrlArgs(), ...args} window.location.href = ( - `/#${this.parseUrlFragment()}?${this.fragmentFromArgs(args)}` + `${window.location.pathname}#${this.parseUrlFragment()}?${this.fragmentFromArgs(args)}` ) },