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:
+10
-2
@@ -438,7 +438,16 @@ function clearSearch(options: { preferBack?: boolean; targetPath?: string } = {}
|
||||
|
||||
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
|
||||
return
|
||||
}
|
||||
@@ -449,7 +458,6 @@ function clearSearch(options: { preferBack?: boolean; targetPath?: string } = {}
|
||||
: ""
|
||||
const canRestoreWithBack =
|
||||
options.preferBack !== false &&
|
||||
!!currentQuery &&
|
||||
searchReturnPath.value === targetPath &&
|
||||
backPath === targetPath
|
||||
|
||||
|
||||
Reference in New Issue
Block a user