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
This commit is contained in:
anime
2025-07-07 20:36:10 +08:00
parent 5e6fa26c90
commit 0930fa269c

View File

@@ -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}`
}
}