Skip to content

Commit 2bc548e

Browse files
committed
feat: handle url search params
1 parent b788abb commit 2bc548e

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/getValue.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,28 @@ const getValue = (element) => {
122122
value = localStorage.getItem('clientId')
123123
else if (value === '$session_id')
124124
value = localStorage.getItem('session_id')
125-
else if ([
125+
else if (value.startsWith('$search')) {
126+
const searchParams = new URLSearchParams(window.location.search);
127+
if (value.includes('.')) {
128+
value = searchParams.get(value.split('.')[1]);
129+
} else {
130+
const paramsObject = {};
131+
132+
// Iterate over all key-value pairs and add them to the object
133+
for (const [key, value] of searchParams) {
134+
paramsObject[key] = value;
135+
}
136+
value = paramsObject
137+
}
138+
139+
} else if ([
126140
'$href',
127141
'$origin',
128142
'$protocol',
129143
'$host',
130144
'$hostname',
131145
'$port',
132146
'$pathname',
133-
'$search',
134147
'$hash'
135148
].includes(value)) {
136149
value = window.location[value.substring(1)]

0 commit comments

Comments
 (0)