diff --git a/src/app/router.js b/src/app/router.js index fd826fdf..01841fab 100644 --- a/src/app/router.js +++ b/src/app/router.js @@ -1,7 +1,12 @@ import Routes from "./routes"; import userService from "../features/UserService"; +import { Store } from "../features"; + +const store = Store.getInstance(); export const historyRouter = (path) => { + store.clearListeners(); + const pathToGo = interceptor(path); history.pushState({}, "", pathToGo); @@ -14,6 +19,8 @@ export const historyRouter = (path) => { }; export const hashRouter = (hash) => { + store.clearListeners(); + const path = hash.replace("#", ""); const pathToGo = interceptor(path); diff --git a/src/features/Store.js b/src/features/Store.js index 67fee2b3..4a919e3c 100644 --- a/src/features/Store.js +++ b/src/features/Store.js @@ -19,6 +19,10 @@ const Store = (function () { listeners.add(listener); return () => listeners.delete(listener); }, + + clearListeners: () => { + listeners.clear(); + }, }; }; diff --git a/src/widgets/Header.js b/src/widgets/Header.js index 71203bb8..29ba7f45 100644 --- a/src/widgets/Header.js +++ b/src/widgets/Header.js @@ -12,7 +12,9 @@ const Header = () => { : { href: "/login", title: "로그인" }, ]; - const currentPath = window.location.pathname; + const currentPath = + window.location.hash?.replace("#", "") || window.location.pathname; + const isCurrNav = (path) => path === currentPath; const navTextColor = (path) => (isCurrNav(path) ? "blue-600" : "gray-600"); const navFontWeight = (path) => (isCurrNav(path) ? "bold" : "");