Skip to content

Commit a864569

Browse files
authored
fix(toolkit): prevent appending "?" to URL when no filters are active (#8180)
1 parent 2dc0ff5 commit a864569

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

assets/js/toolkit.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -248,17 +248,15 @@ function applyFilters(filtersParams) {
248248

249249
// Apply current filters to URL
250250
function applyFiltersToURL(filterParams) {
251-
let filters = ''
252-
for (let key in filterParams) {
253-
if (filterParams[key].length) {
254-
filters = filters + `${key}=${filterParams[key].join(',')}&`
255-
}
256-
}
257-
// Remove extra &
258-
if (filters) {
259-
filters = filters.slice(0, filters.length - 1)
251+
const url = new URL(window.location)
252+
const params = new URLSearchParams()
253+
254+
for (const [key, values] of Object.entries(filterParams)) {
255+
values.forEach(value => params.append(key, value))
260256
}
261-
window.history.replaceState(null, '', `?${filters}`)
257+
258+
url.search = params.toString()
259+
window.history.replaceState(null, '', url)
262260
}
263261

264262
// Apply URL to filters

0 commit comments

Comments
 (0)