From ac7f07b4153005939728f012e80be6b59d793a91 Mon Sep 17 00:00:00 2001 From: MooKorea <69235304+MooKorea@users.noreply.github.com> Date: Sun, 29 Oct 2023 20:34:13 -0500 Subject: [PATCH] fix documentation home 404 --- src/assets/pages/documentation/Body.jsx | 11 ++++++++--- src/assets/pages/documentation/Sidebar.jsx | 5 ++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/assets/pages/documentation/Body.jsx b/src/assets/pages/documentation/Body.jsx index 49c8e97..1cd25b3 100644 --- a/src/assets/pages/documentation/Body.jsx +++ b/src/assets/pages/documentation/Body.jsx @@ -2,16 +2,21 @@ import React, { useEffect, useState } from "react"; import { motion } from "framer-motion"; import Image from "./Image"; import parse, { domToReact } from "html-react-parser"; -import { useParams } from "react-router-dom"; +import { useNavigate, useParams } from "react-router-dom"; +import { firstItem } from "./Sidebar"; export default function Body() { const [HTML, setHTML] = useState(); const { id } = useParams(); + const navigate = useNavigate() useEffect(() => { (async () => { setHTML(null); - if (id === "home") return; + if (id === "home") { + navigate(`/documentation/${firstItem}`) + return + } const data = await fetch(`/docs/${id.replace("--", "/")}.html`); if (data.status === 404) { setHTML(`${id}.md does not exist in the github repository`); @@ -79,7 +84,7 @@ export default function Body() { ); } - + return ( { @@ -34,7 +36,8 @@ export default function Sidebar() { return handleSidebarItems(e, i); }); //navigate to first item - navigate(itemArr[0].props.values.slice(0, -3)); + firstItem = itemArr[0].props.values.slice(0, -3) + navigate(firstItem); setItems(itemArr); })(); }, []);