diff --git a/src/pages/article/index.tsx b/src/pages/article/index.tsx index b266366..3ead850 100644 --- a/src/pages/article/index.tsx +++ b/src/pages/article/index.tsx @@ -1,5 +1,5 @@ import { useState, useMemo, useCallback } from 'react' -import Taro, { useRouter } from '@tarojs/taro' +import Taro from '@tarojs/taro' import { View, Text, Image, ScrollView, Input } from '@tarojs/components' import { Icon } from '@antmjs/vantui' import { getArticleDetail } from '@/mock/articleDetail' @@ -14,9 +14,7 @@ function getStatusBarH(): number { } export default function ArticleDetail() { - // useRouter 在部分 Taro 版本首次渲染 params 为空,用 getCurrentInstance 兜底 - const router = useRouter() - const id = router.params.id || Taro.getCurrentInstance().router?.params?.id + const id = String(Taro.getCurrentInstance().router?.params?.id || 1) const article = useMemo(() => (id ? getArticleDetail(id) : null), [id]) const [commentText, setCommentText] = useState('') const [commentList, setCommentList] = useState(comments)