From ee51cb8248cd119276e2aaaf0b326a67d225869d Mon Sep 17 00:00:00 2001 From: Dana Date: Wed, 18 Dec 2024 04:01:28 +0900 Subject: [PATCH] =?UTF-8?q?chore:=20=EC=BD=94=EB=93=9C=20=EC=A0=95?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/initApp.js | 28 ++++++++++++++++++++++++++++ src/main.js | 24 ++---------------------- 2 files changed, 30 insertions(+), 22 deletions(-) create mode 100644 src/initApp.js diff --git a/src/initApp.js b/src/initApp.js new file mode 100644 index 00000000..8a99ad65 --- /dev/null +++ b/src/initApp.js @@ -0,0 +1,28 @@ +import { router } from "./app/router"; + +const initLoadedListener = () => { + document.addEventListener("DOMContentLoaded", () => { + const currentPath = window.location.hash || window.location.pathname; + router(currentPath); + }); +}; + +const initPopListener = () => { + window.addEventListener("popstate", () => { + const currentPath = window.location.hash || window.location.pathname; + router(currentPath); + }); +}; + +const initHashChangeListener = () => { + window.addEventListener("hashchange", () => { + const currentPath = window.location.hash || window.location.pathname; + router(currentPath); + }); +}; + +export const initApp = () => { + initPopListener(); + initHashChangeListener(); + initLoadedListener(); +}; diff --git a/src/main.js b/src/main.js index d01308c4..732925c5 100644 --- a/src/main.js +++ b/src/main.js @@ -1,23 +1,3 @@ -import { router } from "./app/router"; +import { initApp } from "./initApp"; -const initPopListener = () => { - window.addEventListener("popstate", () => { - const currentPath = window.location.hash || window.location.pathname; - router(currentPath); - }); -}; - -const initHashChangeListener = () => { - window.addEventListener("hashchange", () => { - const currentPath = window.location.hash || window.location.pathname; - router(currentPath); - }); -}; - -initPopListener(); -initHashChangeListener(); - -document.addEventListener("DOMContentLoaded", () => { - const currentPath = window.location.hash || window.location.pathname; - router(currentPath); -}); +initApp();