swr과 swrConfig를 사용하여 낙관적 업데이트를 하기 위해 키들을
const profileKey = `api/profiles/${article.author.username}`;
const commentsKey = `api/articles/${slug}/comments`;
const articleKey = `api/articles/${slug}`;
이렇게 설정해 놨는데
이상하게 요청을 보낼때
안되어서 확인해보니
앞에 해당 라우트 페이지의 경로가 추가적으로 붙는 거였다
/article/api/articles/article-28-6030
그래서 검색해보니
주소를 넣을 때 앞에 /을 붙이지 않으면 상대경로로 인식해 자동으로 해당 라우트를 붙인다고 한다.
그래서 최종적으로
const profileKey = `/api/profiles/${article.author.username}`;
const commentsKey = `/api/articles/${slug}/comments`;
const articleKey = `/api/articles/${slug}`;
이렇게 생성
'개발 > NEXTJS' 카테고리의 다른 글
| nextjs jwt 토큰에서 만료 값 읽어와서 쿠키 설정하기 (0) | 2025.03.02 |
|---|---|
| api router에서 params 가져오는 법 (0) | 2025.02.26 |
| useOptimistic과 startTransition (0) | 2025.02.25 |
| "Bearer Token Authentication" 방식에서 쿠키 기반 인증 시스템으로 마이그레이션 (0) | 2025.02.24 |
| nextjs에서 사용자 정보를 swr과 zustand를 사용하여 관리하기 (0) | 2025.02.23 |