Cleanup updateQueryString composable
This commit is contained in:
parent
f61fafec2a
commit
934f802be2
2 changed files with 3 additions and 9 deletions
|
|
@ -1,9 +1,5 @@
|
|||
export default (uri: string, key: string, value: string) => {
|
||||
const re = new RegExp(`([?&])${key}=.*?(&|$)`, 'i')
|
||||
if (uri.match(re)) {
|
||||
return uri.replace(re, `$1${key}=${value}$2`)
|
||||
} else {
|
||||
const separator = uri.indexOf('?') !== -1 ? '&' : '?'
|
||||
return `${uri}${separator}${key}=${value}`
|
||||
}
|
||||
const url = new URL(uri)
|
||||
url.searchParams.set(key, value)
|
||||
return url.href
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue