From ad612cde0f6b3b98241895126f170ac75c93bd7b Mon Sep 17 00:00:00 2001 From: wonderlandpark Date: Sun, 7 Mar 2021 20:53:38 +0900 Subject: [PATCH] chore: prevent showing 404 at loading --- pages/developers/docs/[first]/[second].tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pages/developers/docs/[first]/[second].tsx b/pages/developers/docs/[first]/[second].tsx index 11f4d69..7c08144 100644 --- a/pages/developers/docs/[first]/[second].tsx +++ b/pages/developers/docs/[first]/[second].tsx @@ -15,19 +15,23 @@ const Markdown = dynamic(() => import ('@components/Markdown')) const docsDir = './api-docs/docs' const Docs: NextPage = ({ docs }) => { const router = useRouter() - const [ document, setDoc ] = useState({ name: 'Init' }) + const [ document, setDoc ] = useState(null) useEffect(() => { + if(!router.query.first) return let res = docs?.find(el => el.name === router.query.first) if(router.query.second) res = res?.list?.find(el => el.name === router.query.second) - setDoc(res) + setDoc(res || { name: 'Not Found' }) setTimeout(highlightBlocks, 100) }, [docs, router.query]) useEffect(() => highlightBlocks, [document]) - if((!document) || router.query.docs?.length > 2) return + if(document?.name === 'Not Found') return return -
- +
+ { + !document ? '' + : + }
}