Skip to content

Commit

Permalink
fix documentation home 404
Browse files Browse the repository at this point in the history
  • Loading branch information
MooKorea committed Oct 30, 2023
1 parent dac966c commit ac7f07b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/assets/pages/documentation/Body.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down Expand Up @@ -79,7 +84,7 @@ export default function Body() {
</div>
);
}

return (
<motion.div
initial={{ opacity: 0, y: 20 }}
Expand Down
5 changes: 4 additions & 1 deletion src/assets/pages/documentation/Sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { useMediaQuery } from "../../hooks/useMediaQuery";
import { motion, useAnimation } from "framer-motion";
import { useNavigate } from "react-router-dom";

export let firstItem;

export default function Sidebar() {
//loop through TOC
const handleSidebarItems = (data, index) => {
Expand Down Expand Up @@ -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);
})();
}, []);
Expand Down

0 comments on commit ac7f07b

Please sign in to comment.