404.js 502 B

12345678910111213141516171819
  1. import Router from "next/router";
  2. import { useEffect, useState } from "react";
  3. export default function Custom404() {
  4. const [isNotFound, setIsNotFound] = useState(false);
  5. useEffect(() => {
  6. const pathNameArray = window.location.pathname.split("/");
  7. if (pathNameArray.length == 2 && pathNameArray[1] == "404") {
  8. setIsNotFound(true);
  9. } else {
  10. Router.replace(window.location.pathname);
  11. }
  12. }, []);
  13. if (isNotFound) return <h1>404 - Page Not Found</h1>;
  14. return null;
  15. }