123456789101112131415161718192021 |
- export function parseUrlParams(url: string): Record<string, string> {
- const params: Record<string, string> = {};
- const queryString = url.split('?')[1];
- if (!queryString) {
- return params; // 没有查询参数,返回空对象
- }
- const pairs = queryString.split('&');
- for (const pair of pairs) {
- const [key, value] = pair.split('=');
- if (key) {
- params[decodeURIComponent(key)] = value ? decodeURIComponent(value) : '';
- }
- }
- return params;
- }
|