Better logic on the UI to parse the current URL fragment arguments.

This commit is contained in:
Fabio Manganiello 2023-12-13 21:46:07 +01:00
parent 9beb10c373
commit 8bbafd2f7d
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774

View file

@ -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('=')
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)}`
)
},