Skip to content

Commit

Permalink
Fix url to match query string for sharing and back button
Browse files Browse the repository at this point in the history
  • Loading branch information
scosman committed Jul 28, 2024
1 parent 4d50beb commit 8f48fc9
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/routes/(marketing)/search/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { browser } from "$app/environment"
import { onMount } from "svelte"
import Fuse from "fuse.js"
import { goto } from "$app/navigation"
const fuseOptions = {
keys: ["title", "description", "body"],
Expand All @@ -28,9 +29,6 @@
loading = false
})
// searchQuery is $page.url.hash minus the "#" at the beginning if present
let searchQuery = decodeURIComponent($page.url.hash.slice(1) ?? "")
type Result = {
item: {
title: string
Expand All @@ -40,16 +38,18 @@
}
}
let results: Result[] = []
// searchQuery is $page.url.hash minus the "#" at the beginning if present
let searchQuery = decodeURIComponent($page.url.hash.slice(1) ?? "")
$: {
if (fuse) {
results = fuse.search(searchQuery)
}
}
// Update the URL hash when searchQuery changes so the browser can bookmark/share the search results
$: {
if (browser) {
window.location.hash = "#" + searchQuery
goto("#" + searchQuery, { keepFocus: true })
}
}
</script>
Expand Down

0 comments on commit 8f48fc9

Please sign in to comment.