fix: Switching language error on tabbed pages, add 404 page

This commit is contained in:
radishzzz 2025-03-15 13:55:06 +00:00
parent a61b299b51
commit 2a9500089c
4 changed files with 35 additions and 12 deletions

View file

@ -1,6 +1,6 @@
---
import { getNextLangUrl, getPostNextLangUrl } from '@/i18n/path'
import { isPostPage } from '@/utils/page'
import { isPostPage, isTagPage } from '@/utils/page'
interface Props {
supportedLangs: string[]
@ -9,10 +9,15 @@ interface Props {
const { supportedLangs } = Astro.props
const currentPath = Astro.url.pathname
const isPost = isPostPage(currentPath)
const isTag = isTagPage(currentPath)
const nextUrl = isPost
? getPostNextLangUrl(currentPath, supportedLangs)
: getNextLangUrl(currentPath)
// 检查是否应使用受限的语言列表
const useFilteredLangs = isPost || (isTag && supportedLangs.length > 0)
// 根据页面类型选择合适的语言切换方式
const nextUrl = useFilteredLangs
? getPostNextLangUrl(currentPath, supportedLangs) // 只在有内容的语言间切换
: getNextLangUrl(currentPath) // 在所有语言间切换
---
<a