diff --git a/frontend/pages/_app.js b/frontend/pages/_app.js index ef69d06c..27a9ece7 100644 --- a/frontend/pages/_app.js +++ b/frontend/pages/_app.js @@ -26,6 +26,16 @@ export default function CachingApp({ Component, pageProps }) { const router = useRouter(); + useEffect(() => { + if ( + router.pathname !== "/entry-point" && + window && + localStorage.getItem("entry_point") + ) { + localStorage.removeItem("entry_point"); + } + }, [router]); + useEffect(() => { const handleStart = () => { NProgress.start(); diff --git a/frontend/pages/entry-point.js b/frontend/pages/entry-point.js new file mode 100644 index 00000000..305c41f1 --- /dev/null +++ b/frontend/pages/entry-point.js @@ -0,0 +1,29 @@ +import { useRouter } from "next/router"; +import { useContext, useLayoutEffect } from "react"; + +import UserContext from "../src/core/providers/UserProvider/context"; +import { getLayout } from "../src/layouts/EntryPointLayout"; + +const EntryPoint = () => { + const router = useRouter(); + const { isInit } = useContext(UserContext); + + useLayoutEffect(() => { + if (router.isReady && isInit && router.asPath !== router.pathname + `/`) { + if (localStorage.getItem("entry_point")) { + router.replace("/404", router.asPath); + } else { + localStorage.setItem("entry_point", 1); + router.replace(router.asPath, undefined, { + shallow: true, + }); + } + } + }, [router, isInit]); + + return ""; +}; + +EntryPoint.getLayout = getLayout; + +export default EntryPoint; diff --git a/frontend/src/layouts/EntryPointLayout.js b/frontend/src/layouts/EntryPointLayout.js new file mode 100644 index 00000000..88319d46 --- /dev/null +++ b/frontend/src/layouts/EntryPointLayout.js @@ -0,0 +1,9 @@ +import React from "react"; + +const EntryPointLayout = (props) => { + return props.children; +}; + +export const getLayout = (page) => {page}; + +export default EntryPointLayout;