forked from platypush/platypush
Better logic on the UI to parse the current URL fragment arguments.
This commit is contained in:
parent
9beb10c373
commit
8bbafd2f7d
1 changed files with 10 additions and 6 deletions
|
@ -3,24 +3,28 @@ export default {
|
||||||
name: "Url",
|
name: "Url",
|
||||||
methods: {
|
methods: {
|
||||||
parseUrlFragment() {
|
parseUrlFragment() {
|
||||||
return window.location.href.replace(/.*#(\w+)[?;]?.*/, '$1')
|
return window.location.hash.replace(/^#/, '').replace(/\?.*/, '')
|
||||||
},
|
},
|
||||||
|
|
||||||
getUrlArgs() {
|
getUrlArgs() {
|
||||||
return window.location.href
|
const argsString = window.location.hash.split('?').slice(1)
|
||||||
.replace(/.*#/, '')
|
if (!argsString.length)
|
||||||
.replace(/.*\?/, '')
|
return {}
|
||||||
|
|
||||||
|
return argsString[0]
|
||||||
.split(/[&;]/)
|
.split(/[&;]/)
|
||||||
.reduce((acc, obj) => {
|
.reduce((acc, obj) => {
|
||||||
const tokens = obj.split('=')
|
const tokens = obj.split('=')
|
||||||
|
if (tokens[0]?.length)
|
||||||
acc[tokens[0]] = tokens[1]
|
acc[tokens[0]] = tokens[1]
|
||||||
return acc
|
return acc
|
||||||
}, {})
|
}, {})
|
||||||
},
|
},
|
||||||
|
|
||||||
setUrlArgs(args) {
|
setUrlArgs(args) {
|
||||||
|
args = {...this.getUrlArgs(), ...args}
|
||||||
window.location.href = (
|
window.location.href = (
|
||||||
`/#${this.parseUrlFragment()}?${this.fragmentFromArgs(args)}`
|
`${window.location.pathname}#${this.parseUrlFragment()}?${this.fragmentFromArgs(args)}`
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue