import "./styles.css"; import styles from "./styles.module.css"; import { pluckPathnameAffixes, useRedirectEntries } from "#theme/NotFound/Content/utils.ts"; import { RewriteIndex } from "@goauthentik/docusaurus-theme/redirects"; import { Redirect } from "@docusaurus/router"; import Translate from "@docusaurus/Translate"; import Heading from "@theme/Heading"; import type { Props } from "@theme/NotFound/Content"; import clsx from "clsx"; import React, { memo, useEffect, useState } from "react"; const NotFound: React.FC = ({ className }) => { return (
Page not found

The page you are looking for may have moved or been deleted. Try using the search bar above to find what you are looking for.

); }; interface RedirectFoundProps extends Props { nextURL: string; } const RedirectFound: React.FC = ({ nextURL, className }) => { const usingRouter = nextURL.startsWith("/"); useEffect(() => { console.debug("Redirecting...", { nextURL, usingRouter }); if (usingRouter) return; window.location.assign(nextURL); }, [nextURL, usingRouter]); return (
This page has moved

Redirecting...

{nextURL}

{usingRouter ? : null}
); }; const NotFoundContentRouter: React.FC = (props) => { const [routeURL, setRouteURL] = useState(); const redirects = useRedirectEntries(); useEffect(() => { setRouteURL(new URL(window.location.href)); }, []); if (typeof routeURL === "undefined") { return null; } const rewritesIndex = new RewriteIndex(redirects ?? []); const [pathname, suffix] = pluckPathnameAffixes(routeURL); const destination = rewritesIndex.finalDestination(pathname); // Is there somewhere to redirect to that isn't the current pathname? if (!destination || destination === pathname) { console.debug("No redirect found", { pathname, suffix, destination }); return ; } const nextURL = destination + suffix; console.debug("Redirect found", { pathname, suffix, destination, nextURL }); // eslint-disable-next-line react-hooks/immutability document.documentElement.dataset.redirect = "pending"; return ; }; export default memo(NotFoundContentRouter);