Skip to content

Commit fc132c0

Browse files
committed
fix toUrl
1 parent f50586f commit fc132c0

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/utils/routes.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ export const getProtocol = () => (import.meta.env.PROD ? "https" : "http");
77
export const getHost = () =>
88
import.meta.env.PROD ? window.location.host : window.location.host;
99

10+
export const toQueryString = (search: string | Record<string, string>) => {
11+
return typeof search === "string"
12+
? search
13+
: new URLSearchParams(search).toString();
14+
};
15+
1016
export const toUrl = (
1117
pathname: string,
1218
search?: string | Record<string, string>
1319
) => {
14-
const searchParams =
15-
typeof search === "string"
16-
? search
17-
: new URLSearchParams(search).toString();
18-
return `${pathname}?${searchParams}`;
20+
return `${pathname}${search ? `?${toQueryString(search)}` : ""}`;
1921
};
2022

2123
export const toPath = (path: PageRoutes | ApiRoutes, params?: object) => {

0 commit comments

Comments
 (0)