forked from platypush/platypush
[UI] Better parsing of the parameter types in getUrlArgs
and setUrlArgs
.
This commit is contained in:
parent
db34a607e4
commit
818f60a468
1 changed files with 31 additions and 3 deletions
|
@ -15,8 +15,22 @@ export default {
|
||||||
.split(/[&;]/)
|
.split(/[&;]/)
|
||||||
.reduce((acc, obj) => {
|
.reduce((acc, obj) => {
|
||||||
const tokens = obj.split('=')
|
const tokens = obj.split('=')
|
||||||
if (tokens[0]?.length)
|
let key = tokens[0]
|
||||||
acc[tokens[0]] = decodeURIComponent(tokens[1])
|
let value = tokens.slice(1).join('=')
|
||||||
|
|
||||||
|
if (value === 'true')
|
||||||
|
value = true
|
||||||
|
else if (value === 'false')
|
||||||
|
value = false
|
||||||
|
else if (value.match(/^-?\d+$/))
|
||||||
|
value = parseInt(value)
|
||||||
|
else if (value.match(/^-?\d+\.\d+$/))
|
||||||
|
value = parseFloat(value)
|
||||||
|
else
|
||||||
|
value = decodeURIComponent(value)
|
||||||
|
|
||||||
|
if (key?.length)
|
||||||
|
acc[key] = value
|
||||||
return acc
|
return acc
|
||||||
}, {})
|
}, {})
|
||||||
},
|
},
|
||||||
|
@ -29,10 +43,24 @@ export default {
|
||||||
acc[key] = value
|
acc[key] = value
|
||||||
else if (curArgs[key] != null)
|
else if (curArgs[key] != null)
|
||||||
delete curArgs[key]
|
delete curArgs[key]
|
||||||
|
|
||||||
|
return acc
|
||||||
|
}, {})
|
||||||
|
|
||||||
|
args = Object.entries({...curArgs, ...args})
|
||||||
|
.reduce((acc, [key, value]) => {
|
||||||
|
// Serialize boolean values
|
||||||
|
if (typeof value === 'boolean')
|
||||||
|
value = value.toString()
|
||||||
|
|
||||||
|
// Serialize numbers
|
||||||
|
if (typeof value === 'number')
|
||||||
|
value = value.toString()
|
||||||
|
|
||||||
|
acc[key] = value
|
||||||
return acc
|
return acc
|
||||||
}, {})
|
}, {})
|
||||||
|
|
||||||
args = {...curArgs, ...args}
|
|
||||||
let location = `${window.location.pathname}#${this.parseUrlFragment()}`
|
let location = `${window.location.pathname}#${this.parseUrlFragment()}`
|
||||||
if (Object.keys(args).length)
|
if (Object.keys(args).length)
|
||||||
location += `?${this.fragmentFromArgs(args)}`
|
location += `?${this.fragmentFromArgs(args)}`
|
||||||
|
|
Loading…
Reference in a new issue