From 0930fa269c999044dbc8d1e0789545e0e6b419a4 Mon Sep 17 00:00:00 2001 From: anime Date: Mon, 7 Jul 2025 20:36:10 +0800 Subject: [PATCH] fix(search): handle cases where slug is undefined - Extract searchResult to a variable for clarity - Implement fallback mechanism to use objectID or article ID when slug is unavailable - Prevent potential navigation errors with missing slug --- components/AlgoliaSearchModal.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/AlgoliaSearchModal.js b/components/AlgoliaSearchModal.js index f398c461..60c04dfa 100644 --- a/components/AlgoliaSearchModal.js +++ b/components/AlgoliaSearchModal.js @@ -104,7 +104,8 @@ export default function AlgoliaSearchModal({ cRef }) { // 跳转Search结果 const onJumpSearchResult = () => { if (searchResults.length > 0) { - window.location.href = `${siteConfig('SUB_PATH', '')}/${searchResults[activeIndex].slug}` + const searchResult = searchResults[activeIndex] + window.location.href = `${siteConfig('SUB_PATH', '')}/${searchResult.slug || searchResult.objectID}` } }