diff --git a/src/pages/PostRedirect/index.tsx b/src/pages/PostRedirect/index.tsx index 99f9a7f..7bd2f84 100644 --- a/src/pages/PostRedirect/index.tsx +++ b/src/pages/PostRedirect/index.tsx @@ -2,6 +2,7 @@ import { useEffect } from "react"; import { useNavigate, useParams } from "react-router-dom"; import { getJSON } from "../../api"; import { langQuery, useI18n } from "../../i18n"; +import { useLocalizedPath } from "../../useLocalizedPath"; import { MOCK_POSTS } from "../../mocks/mockPosts"; import { POST_STREAM_USES_MOCK } from "../../components/messageStream/hooks/usePostStream"; import type { Post } from "../../types/post"; @@ -10,17 +11,18 @@ export function PostRedirect() { const { id } = useParams(); const { lang } = useI18n(); const navigate = useNavigate(); + const lp = useLocalizedPath(); useEffect(() => { if (!id) { - navigate("/browse", { replace: true }); + navigate(lp("/browse"), { replace: true }); return; } if (POST_STREAM_USES_MOCK) { const post = MOCK_POSTS.find((p) => p.id === id); navigate( - post ? `/browse?post=${encodeURIComponent(post.id)}` : "/browse", + lp(post ? `/browse?post=${encodeURIComponent(post.id)}` : "/browse"), { replace: true, }, @@ -32,12 +34,12 @@ export function PostRedirect() { `/api/posts/${id}?lang=${encodeURIComponent(langQuery(lang))}`, ) .then((post) => { - navigate(`/browse?post=${encodeURIComponent(post.id)}`, { + navigate(lp(`/browse?post=${encodeURIComponent(post.id)}`), { replace: true, }); }) - .catch(() => navigate("/browse", { replace: true })); - }, [id, lang, navigate]); + .catch(() => navigate(lp("/browse"), { replace: true })); + }, [id, lang, navigate, lp]); return