TIL

241013

playhong 2024. 10. 13. 23:25

가취뽀 - 회원가입/로그인페이지에 이미 로그인한 사용자가 접근하는 것을 막기

문제발생

import { useRouter } from 'next/router';

const { isLoggedIn } = useAuthStore();
  const router = useRouter();

  // 이미 로그인한 사용자인지 구분해서 접근막기
  useEffect(() => {
    if (isLoggedIn) {
      router.replace('/');
    }
  }, [isLoggedIn, router]);

오류: NextRouter가 마운트되지 않았습니다. https://nextjs.org/docs/messages/next-router-not-mounted

 

원인추론

https://nextjs.org/docs/messages/next-router-not-mounted

위는 공식문서

 

해결방안

 

공식문서에는 next/navigation으로 마이그레이션 하라고 되어있다. 

next/router로 되어있는 것을 navigation으로 수정하지 제대로 된다!

 

참고) https://velog.io/@meek/Error-NextRouter-was-not-mounted-%ED%95%B4%EA%B2%B0%ED%95%98%EA%B8%B0

 


 

 

 

 

'TIL' 카테고리의 다른 글

241015  (0) 2024.10.15
241014  (0) 2024.10.14
241012  (0) 2024.10.12
241011  (0) 2024.10.12
241008  (0) 2024.10.09