index.ts
1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* @author : wonseog
* @date : 2021/03/08
* @description : 현재 pathname을 파악 후 App으로 전달
**/
import App from './App';
import {initialTrantition} from "./components/page.transition";
import {addEvent} from "@src/components/add.event";
import './assets/style/PageTransition.scss';
import './assets/style/PageLoader.scss';
window.addEventListener('DOMContentLoaded', () => {
/* add div for page transitions */
(()=> {
const $div = document.createElement('div');
$div.className = "page-transition";
document.body.appendChild($div);
initialTrantition();
})();
(()=> {
const $div = document.createElement('div');
$div.className = "page-loader";
document.body.appendChild($div);
})();
const $App = document.querySelector('#App');
const pathname = window.location.pathname.split('/')[1];
/* change url */
window.addEventListener('popstate', ()=>{
$App && ($App.innerHTML = App(pathname));
});
/* initial render */
$App && ($App.innerHTML = App(pathname));
document.body.addEventListener('click', async (e) => {
await addEvent(e, $App, App);
});
})