diff --git a/web/html/src/components/utils/HashRouter.tsx b/web/html/src/components/utils/HashRouter.tsx deleted file mode 100644 index e99e4358b194..000000000000 --- a/web/html/src/components/utils/HashRouter.tsx +++ /dev/null @@ -1,124 +0,0 @@ -import * as React from "react"; -import { useEffect, useState } from "react"; - -declare var history: any; - -type HashContextType = { - hash?: string | null; - switch?: boolean; - match?: boolean; - goTo: (arg0?: string | null) => void; - back: () => void; - initial: () => void; -}; - -export const HashRouterContext = React.createContext({ - hash: null, - goTo: (hash) => {}, - back: () => {}, - initial: () => {}, -}); - -const hashUrlRegex = /^#\/(.*)$/; - -function hashUrl() { - const match = window.location.hash.match(hashUrlRegex); - return match ? match[1] : undefined; -} - -type HashRouterProps = { - initialPath: string; - children: React.ReactNode; -}; - -const HashRouter = ({ initialPath, children }: HashRouterProps) => { - const [hash, setHash] = useState(initialPath); - - useEffect(() => { - const hash = hashUrl(); - if (hash) { - setHash(hash); - } else { - initial(); - } - window.addEventListener("popstate", (event) => { - setHash(hashUrl()); - }); - }, []); - - const goTo = (hash?: string | null): void => { - if (hash) { - history.pushState(null, "", "#/" + hash); - setHash(hash); - } else { - initial(); - } - }; - - const replaceWith = (hash: string): void => { - history.replaceState(null, "", "#/" + hash); - setHash(hash); - }; - - const back = () => { - history.back(); - }; - - const initial = () => { - replaceWith(initialPath); - }; - - return ( - - {children} - - ); -}; - -type RouterProps = { - path: string; - children: React.ReactNode | ((arg0: HashContextType) => React.ReactNode | void); -}; - -const Route = ({ path, children }: RouterProps) => { - return ( - - {(context) => { - const match = path === context.hash; - if (context.switch) { - if (match) { - if (typeof children === "function") { - return children({ match: true, ...context }); - } else { - return children; - } - } else { - return null; - } - } else { - if (typeof children === "function") { - return children({ match: match, ...context }); - } else { - return children; - } - } - }} - - ); -}; - -type SwitchProps = { - children: React.ReactNode; -}; - -const Switch = ({ children }: SwitchProps) => { - return ( - - {(context) => ( - {children} - )} - - ); -}; - -export { HashRouter, Route, Switch }; diff --git a/web/html/src/components/utils/index.ts b/web/html/src/components/utils/index.ts index 51704b3b8ccc..9be7cf8aa199 100644 --- a/web/html/src/components/utils/index.ts +++ b/web/html/src/components/utils/index.ts @@ -1,5 +1,4 @@ export * from "./cloneReactElement"; -export * from "./HashRouter"; export * from "./HelpIcon"; export * from "./HelpLink"; export * from "./Loading";