본문 바로가기

Study/Next.js

[Next.js] useLocation, useNavigate, useRouter in Next

 

react-router-dom의 useLocation, useNavigate, useRouter 의 기능을

Next.js에서는 'next/router'의 useRouter 로 구현할 수 있다.

 

import { useRouter } from "next/router";
 ...
const router = useRouter();

  useEffect(() => {
    if (window.location.href.includes("access_token")) {
      window.localStorage.setItem(
        "token",
        window.location.href.split("=")[1].split("&")[0] ?? "none",
      );
      router.push("/");
    }
  }, []);

'Study > Next.js' 카테고리의 다른 글

[Next.js] React와의 차이점  (0) 2023.01.05
[Next.js] Dynamic Import  (0) 2023.01.05
[Next.js] svg component in Next  (1) 2023.01.05
[Next.js] Styled-Components in Next  (0) 2023.01.05
Next.js next/Link  (0) 2023.01.05