Codificar correctamente los parámetros de búsqueda
This commit is contained in:
parent
1ff252e328
commit
4151338500
1 changed files with 4 additions and 3 deletions
|
@ -16,10 +16,10 @@ export default class extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
connect () {
|
connect () {
|
||||||
const q = window.location.search.match(/^\?q=(?<q>.*)&?/)
|
const q = new URLSearchParams(window.location.search).get('q').trim()
|
||||||
|
|
||||||
if (q) {
|
if (q) {
|
||||||
this.qTarget.value = decodeURI(q.groups.q)
|
this.qTarget.value = q
|
||||||
this.search()
|
this.search()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,8 +52,9 @@ export default class extends Controller {
|
||||||
const template = await request.text()
|
const template = await request.text()
|
||||||
const html = await this.engine.parseAndRender(template, { q, site, results })
|
const html = await this.engine.parseAndRender(template, { q, site, results })
|
||||||
const title = `${site.i18n.search.title} - ${q}`
|
const title = `${site.i18n.search.title} - ${q}`
|
||||||
|
const query = new URLSearchParams({ q })
|
||||||
|
|
||||||
window.history.pushState({ q }, title, `?q=${encodeURI(q)}`)
|
window.history.pushState({ q }, title, `?${query.toString()}`)
|
||||||
document.title = title
|
document.title = title
|
||||||
|
|
||||||
main.innerHTML = html
|
main.innerHTML = html
|
||||||
|
|
Loading…
Reference in a new issue