fix: clicking search result no longer redirects to category page

When clicking a search result, showDetail navigates to the detail page.
The route.fullPath watcher then clears searchQuery, which propagates to
Header's localSearch watcher, which emits @search='', which calls
updateSearchQuery(''). This in turn called clearSearch(), which did a
router.replace() to the category page because it didn't check whether
the current route actually had a search query.

The fix: in clearSearch(), if there's no search query in the current
URL, just clear reactive state and return without navigating. This
breaks the circular flow that was overwriting the detail-page
navigation.
This commit is contained in:
2026-05-25 15:32:33 +00:00
parent f484ab2606
commit 5b57640949
+10 -2
View File
@@ -438,7 +438,16 @@ function clearSearch(options: { preferBack?: boolean; targetPath?: string } = {}
searchQuery.value = "" searchQuery.value = ""
if (!currentQuery && route.path === targetPath) { // If there's no active search query in the URL, just clear state and don't navigate.
// This prevents unwanted navigation when the search is cleared reactively (e.g.
// route changes to a detail page, which triggers the route watcher to clear
// searchQuery, which flows through Header and back to updateSearchQuery).
if (!currentQuery) {
searchReturnPath.value = null
return
}
if (route.path === targetPath) {
searchReturnPath.value = null searchReturnPath.value = null
return return
} }
@@ -449,7 +458,6 @@ function clearSearch(options: { preferBack?: boolean; targetPath?: string } = {}
: "" : ""
const canRestoreWithBack = const canRestoreWithBack =
options.preferBack !== false && options.preferBack !== false &&
!!currentQuery &&
searchReturnPath.value === targetPath && searchReturnPath.value === targetPath &&
backPath === targetPath backPath === targetPath