"use client"; import React, { useEffect, useState } from "react"; import ReactMarkdown from "react-markdown"; const Page = ({ params }: { params: { slug: string } }) => { const { slug } = params; const [page, setPage] = useState<{ title: string; content: string } | null>( null ); const [loading, setLoading] = useState(true); const [notFound, setNotFound] = useState(false); useEffect(() => { const fetchPage = async () => { try { const response = await fetch(`/api/mdx/pages/${slug}`); if (response.ok) { const data = await response.json(); setPage(data); } else { if (response.status === 404) { setNotFound(true); } } } catch (error) { console.error("Failed to load page", error); setNotFound(true); } finally { setLoading(false); } }; fetchPage(); }, [slug]); if (loading) { return ( Loading... ); } if (notFound) { return ( 404 Page not Found Please return back to Home ); } if (!page) { return null; } return ( {page.title} {page.content} ); }; export default Page;
Loading...
Please return back to Home