diff --git a/src/getUrlAllParams.ts b/src/getUrlAllParams.ts index e38caec..b4dff02 100644 --- a/src/getUrlAllParams.ts +++ b/src/getUrlAllParams.ts @@ -5,8 +5,8 @@ import type { TObject } from './types' * @param url 指定url,默认 location.href */ -export function getUrlAllParams(url: string) { - url = url ? url : window.location.href +export function getUrlAllParams(url?: string) { + url = url ? url : decodeURIComponent(window.location.href) const pa = url.slice(Math.max(0, url.indexOf('?') + 1)), arr = pa.split('&'), result: TObject = {} diff --git a/src/getUrlParams.ts b/src/getUrlParams.ts index 38b021f..f4bf0c7 100644 --- a/src/getUrlParams.ts +++ b/src/getUrlParams.ts @@ -4,7 +4,7 @@ * @param url 指定url,默认 location.href */ -export function getUrlParams(name: string, url: string) { +export function getUrlParams(name: string, url?: string) { const reg = new RegExp(`(^|&)${name}=([^&]*)(&|$)`) let result = null