본문 바로가기

Front-End

[Next] 동적라우팅에서 router.pathname, router.asPath 차이

파일 이름을 
...앞의 경로/completed/[userChallengId].tsx
이렇게 해서 동적라우팅을 구현했었다.

  const router = useRouter();
  const asPath = router.asPath;
  const pathname = router.pathname;
  console.log(asPath);
  console.log(pathname);

 

그러면 아래와 같이 출력된다.

...앞의 경로/completed/651627fb3931e74294dda3ca
...앞의 경로/completed/[userChallengId]

완전 정확한 url을 확인하려면 asPath를 써야한다.