[UI] setUrlArgs should remove args when value == null.

This commit is contained in:
Fabio Manganiello 2023-12-16 18:58:31 +01:00
parent 065f7d74a5
commit 3bc27a505f
Signed by: blacklight
GPG Key ID: D90FBA7F76362774
1 changed files with 16 additions and 4 deletions

View File

@ -22,10 +22,22 @@ export default {
},
setUrlArgs(args) {
args = {...this.getUrlArgs(), ...args}
window.location.href = (
`${window.location.pathname}#${this.parseUrlFragment()}?${this.fragmentFromArgs(args)}`
)
const curArgs = this.getUrlArgs()
args = Object.entries(args)
.reduce((acc, [key, value]) => {
if (value != null)
acc[key] = value
else if (curArgs[key] != null)
delete curArgs[key]
return acc
}, {})
args = {...curArgs, ...args}
let location = `${window.location.pathname}#${this.parseUrlFragment()}`
if (Object.keys(args).length)
location += `?${this.fragmentFromArgs(args)}`
window.location.href = location
},
fragmentFromArgs(args) {