Frontend: run search from root /?q= (redirect to /search?q=)
Visiting /?q=what showed the empty home page instead of results because only /search executes a query. Root now redirects a q param to the canonical results URL. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
3aa08e4a4f
commit
dda197bd83
1 changed files with 8 additions and 0 deletions
|
|
@ -242,6 +242,14 @@ export default {
|
|||
const url = new URL(req.url)
|
||||
|
||||
if (url.pathname === '/') {
|
||||
// Accept a query on the root too (e.g. /?q=what) — redirect to the
|
||||
// canonical results URL so the search actually runs.
|
||||
const q = url.searchParams.get('q')?.trim()
|
||||
if (q) {
|
||||
const page = url.searchParams.get('page')
|
||||
const dest = `/search?q=${encodeURIComponent(q)}${page ? `&page=${encodeURIComponent(page)}` : ''}`
|
||||
return Response.redirect(url.origin + dest, 302)
|
||||
}
|
||||
return new Response(homePage(), { headers: { 'Content-Type': 'text/html; charset=utf-8' } })
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue