From 1dd6756d283cb993c62523341bd7c213929fc654 Mon Sep 17 00:00:00 2001 From: mebtte Date: Tue, 30 Apr 2024 22:44:59 +0800 Subject: [PATCH] improve parse_search --- apps/pwa/src/utils/parse_search.ts | 14 +++----------- apps/pwa/src/utils/use_navigate.ts | 4 +--- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/apps/pwa/src/utils/parse_search.ts b/apps/pwa/src/utils/parse_search.ts index 4dfe5162..6a15f59f 100644 --- a/apps/pwa/src/utils/parse_search.ts +++ b/apps/pwa/src/utils/parse_search.ts @@ -1,15 +1,7 @@ -function parseSearch(search?: string) { - const query: { +function parseSearch(search: string) { + return Object.fromEntries(new URLSearchParams(search).entries()) as { [key in Keys]?: string; - } = {}; - if (search) { - const s = search.replace(/\?/g, ''); - s.split('&').forEach((kv) => { - const [key, value] = kv.split('='); - query[key] = decodeURIComponent(value); - }); - } - return query; + }; } export default parseSearch; diff --git a/apps/pwa/src/utils/use_navigate.ts b/apps/pwa/src/utils/use_navigate.ts index 89875272..a8b6873c 100644 --- a/apps/pwa/src/utils/use_navigate.ts +++ b/apps/pwa/src/utils/use_navigate.ts @@ -15,9 +15,7 @@ function useNavigate() { replace = false, }: { path?: string; - query?: { - [key: string]: number | string | undefined; - }; + query?: Record; replace?: boolean; }) => { const combineQuery = {