Skip to content

Commit

Permalink
Merge pull request #106 from Nubblee/fix/detailRoute-105
Browse files Browse the repository at this point in the history
[fix] 주소창의 postId와 title이 맞아야만 글이 보이도록 수정
  • Loading branch information
jizerozz authored Oct 29, 2024
2 parents 4a21d17 + 4fefb42 commit ed4759b
Show file tree
Hide file tree
Showing 3 changed files with 4,910 additions and 3,029 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
9 changes: 8 additions & 1 deletion src/pages/PostDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface PostData {
}

const PostDetail = () => {
const { postId } = useParams<{ postId: string }>()
const { title, postId } = useParams<{ title: string; postId: string }>()
const [postData, setPostData] = useState<PostData | null>(null)
const [error, setError] = useState<string | null>(null)
const { sessionId } = useAuthStore()
Expand All @@ -34,7 +34,9 @@ const PostDetail = () => {
const handlePostEdit = () => {
navigate(`/write?id=${postId}`, { state: { postData } })
}

console.log(postData)

useEffect(() => {
const fetchPostData = async () => {
try {
Expand All @@ -44,6 +46,11 @@ const PostDetail = () => {
},
})
setPostData(res.data)
console.log(res.data)

if (res.data.title !== title) {
navigate('/error') // 에러 페이지 경로에 맞게 수정
}
} catch (err: unknown) {
if (axios.isAxiosError(err)) {
setError(err.response?.data?.message || '게시글을 가져오는 데 실패했습니다.')
Expand Down
Loading

0 comments on commit ed4759b

Please sign in to comment.