자바스크립트 라우팅 방법 정리하기
히스토리, url관련 문법 정리
- URLSearchParams
- 뒤로가기, 앞으로가기 처리 (feet. addEventListner - popstate)
url 변경
- history.pushState vs location.href
url 파싱
- location.search vs URLSearchParams(location.search)
- 쿼리 가져오기 방법
// 라우팅 this.route = () => { const { pathname } = window.location; if (pathname === '/') { postPage.render(); } else if (pathname.indexOf('/posts/') === 0) { const [, , postId] = pathname.split('/'); postEditPage.setState({ postId }); } }; this.route();
document.location.href = './index.html';