function router() {
//location.hash를 통해 지금 보고있는 화면의 위치 해시값을 받아 목록을 보여줄지 내용을 보여줄지 정한다.
const routePath = location.hash;
if (routePath === "") {
newsFeed(); //routePath 값에 #만 있는 경우 빈 문자열을 출력한다.
} else if (routePath.indexOf("#/page/") >= 0) {
store.currentPage = Number(routePath.substr(7));
newsFeed();
} else {
newsDetail();
}
}
window.addEventListener("hashchange", router); //hash값을 받아 알맞는 라우터를 찾고 보여줄 화면을 지정한다
router();
라우터를 사용하여 이전 EP에서의 화면 전환이 이루어지지 않았던 문제점을 해결한다.