From 8f48fc99eff96cd9b20a56e412408c1069d880eb Mon Sep 17 00:00:00 2001 From: scosman Date: Sun, 28 Jul 2024 17:10:18 -0400 Subject: [PATCH] Fix url to match query string for sharing and back button --- src/routes/(marketing)/search/+page.svelte | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/routes/(marketing)/search/+page.svelte b/src/routes/(marketing)/search/+page.svelte index 89e9c6e4..a6eb9774 100644 --- a/src/routes/(marketing)/search/+page.svelte +++ b/src/routes/(marketing)/search/+page.svelte @@ -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"], @@ -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 @@ -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 }) } }