fix(post): redirect to 404 when thread URL specifies wrong board

This commit is contained in:
plebeius
2025-12-31 20:14:51 +01:00
parent c984e56249
commit 6724f91c79
+9 -1
View File
@@ -2,7 +2,7 @@ import { useEffect } from 'react';
import { useTranslation } from 'react-i18next';
import { Comment, Role, useComment, useEditedComment, useSubplebbit } from '@plebbit/plebbit-react-hooks';
import useSubplebbitsStore from '@plebbit/plebbit-react-hooks/dist/stores/subplebbits';
import { useLocation, useParams } from 'react-router-dom';
import { useLocation, useNavigate, useParams } from 'react-router-dom';
import { isAllView } from '../../lib/utils/view-utils';
import { useResolvedSubplebbitAddress } from '../../hooks/use-resolved-subplebbit-address';
import { useDefaultSubplebbits } from '../../hooks/use-default-subplebbits';
@@ -60,6 +60,14 @@ const PostPage = () => {
const isInAllView = isAllView(location.pathname);
const comment = useComment({ commentCid });
const navigate = useNavigate();
useEffect(() => {
if (comment?.subplebbitAddress && subplebbitAddress && comment.subplebbitAddress !== subplebbitAddress) {
navigate('/not-found', { replace: true });
}
}, [comment?.subplebbitAddress, subplebbitAddress, navigate]);
const subplebbit = useSubplebbit({ subplebbitAddress });
const { shortAddress, title } = subplebbit || {};
const defaultSubplebbits = useDefaultSubplebbits();