Skip to content

Commit

Permalink
chore: 코드 정리
Browse files Browse the repository at this point in the history
  • Loading branch information
dosilv committed Dec 17, 2024
1 parent 78aaeed commit ee51cb8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
28 changes: 28 additions & 0 deletions src/initApp.js
Original file line number Diff line number Diff line change
@@ -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();
};
24 changes: 2 additions & 22 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -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();

0 comments on commit ee51cb8

Please sign in to comment.