index.ts 911 Bytes
/**
 * @author : wonseog
 * @date : 2021/03/08
 * @description : 현재 pathname을 파악 후 App으로 전달
 **/

import "./assets/style/PageTransition.scss";
import "./assets/style/PageLoader.scss";

import renderApp from "./App";
import { animatePage, createLoaderElement } from "./shared/page";
import { getPathname } from "./shared/functions";
import { addEventWithElementByType, linkEvent } from "./shared/event";

window.addEventListener("DOMContentLoaded", () => {
  createLoaderElement();
  animatePage();

  const pathname = getPathname();

  addEventWithElementByType(document.body, "click", function (e: Event) {
    /* add navigation click event */
    if ((e.target as HTMLAnchorElement).matches("[data-link]")) {
      linkEvent(e);
    }
  });

  /* change url */
  window.addEventListener("popstate", () => {
    renderApp(pathname);
  });

  /* initial render */
  renderApp(pathname);
});