history.push vs window.location.href 비교하기

GonnabeAlright·2021년 11월 28일
0
post-thumbnail

history.push vs window.location.href

공통점

  • 다른 페이지로 이동

차이점

history.pushwindow.location.href
HTTP 요청XO
새로고침XO
Application 상태 유지OX

push와 replace의 차이점

Home > Item > Login > Item 순으로 페이지를 이동했을 때 Login 페이지에서 history.push / history.replace 사용시 차이점

1. history.push

Home > Item > Login > Item 순으로 history에 쌓여서 마지막 페이지에서 뒤로가기 버튼을 누르면 Login 페이지로 되돌아간다.

2. history.replace

Home > Item > Item 순으로 history에 쌓여서 마지막 페이지에서 뒤로가기 버튼을 누르면 Item 페이지로 되돌아간다.

history를 스택이라고 가정한다면 push는 history 최상단에 쌓는 것, replace는 history 제일 위에 있는 원소를 지금 넣을 원소로 바꾸는 것(대체하는 것)이다.

0개의 댓글