mirror of
https://github.com/koreanbots/core.git
synced 2025-12-16 14:30:22 +00:00
chore: prevent showing 404 at loading
This commit is contained in:
parent
59f6477719
commit
ad612cde0f
@ -15,19 +15,23 @@ const Markdown = dynamic(() => import ('@components/Markdown'))
|
|||||||
const docsDir = './api-docs/docs'
|
const docsDir = './api-docs/docs'
|
||||||
const Docs: NextPage<DocsProps> = ({ docs }) => {
|
const Docs: NextPage<DocsProps> = ({ docs }) => {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const [ document, setDoc ] = useState<DocsData>({ name: 'Init' })
|
const [ document, setDoc ] = useState<DocsData>(null)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if(!router.query.first) return
|
||||||
let res = docs?.find(el => el.name === router.query.first)
|
let res = docs?.find(el => el.name === router.query.first)
|
||||||
if(router.query.second) res = res?.list?.find(el => el.name === router.query.second)
|
if(router.query.second) res = res?.list?.find(el => el.name === router.query.second)
|
||||||
setDoc(res)
|
setDoc(res || { name: 'Not Found' })
|
||||||
setTimeout(highlightBlocks, 100)
|
setTimeout(highlightBlocks, 100)
|
||||||
}, [docs, router.query])
|
}, [docs, router.query])
|
||||||
|
|
||||||
useEffect(() => highlightBlocks, [document])
|
useEffect(() => highlightBlocks, [document])
|
||||||
if((!document) || router.query.docs?.length > 2) return <NotFound />
|
if(document?.name === 'Not Found') return <NotFound />
|
||||||
return <DeveloperLayout enabled='docs' docs={docs} currentDoc={(router.query.second || router.query.first) as string}>
|
return <DeveloperLayout enabled='docs' docs={docs} currentDoc={(router.query.second || router.query.first) as string}>
|
||||||
<div className='px-2 no-seg'>
|
<div className='px-2'>
|
||||||
<Markdown text={document?.text} options={{ openLinksInNewWindow: false }}/>
|
{
|
||||||
|
!document ? ''
|
||||||
|
: <Markdown text={document.text} options={{ openLinksInNewWindow: false }}/>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
</DeveloperLayout>
|
</DeveloperLayout>
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user