반응형
250x250
Notice
Recent Posts
Recent Comments
Link
관리 메뉴

짧은코딩

Next.JS) Router에서 push와 replace의 차이점 본문

리액트

Next.JS) Router에서 push와 replace의 차이점

5_hyun 2023. 2. 6. 00:31

push

  useEffect(() => {
    if (signUpDone) {
      router.push("/");
    }
  }, [signUpDone]);

push를 사용하면 뒤로가기 버튼을 눌렀을 때, 다시 이전 페이지로 돌아간다.

replace

  const router = useRouter();
  
  useEffect(() => {
    if (me && me.id) {
      router.replace("/");
    }
  }, [me && me.id]);

replace를 사용하면 뒤로가기 버튼을 눌러도 이전 페이지로 돌아가지 못한다.

다시 뒤로 돌아가면 안되는 상황에서는 replace를 사용하는 것이 좋다.

728x90
반응형
Comments