mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(routing): canonicalize board page 1 routes instead of not-found
Board URLs ending in /1 now redirect to the canonical page-1 path while preserving search, hash, and settings suffixes.
This commit is contained in:
@@ -431,11 +431,16 @@ describe('App', () => {
|
|||||||
expect(container.querySelector('[data-testid="board-blotter"]')).toBeTruthy();
|
expect(container.querySelector('[data-testid="board-blotter"]')).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('redirects board page 1 feeds to not-found', async () => {
|
it.each([
|
||||||
await renderApp('/mu/1');
|
['/mu/1', '/mu'],
|
||||||
|
['/mu/1?focus=1', '/mu?focus=1'],
|
||||||
|
['/mu/1/settings?focus=1', '/mu/settings?focus=1'],
|
||||||
|
])('canonicalizes board page 1 route %s to %s', async (initialEntry, expectedLocation) => {
|
||||||
|
await renderApp(initialEntry);
|
||||||
|
|
||||||
expect(latestLocation).toBe('/not-found');
|
expect(latestLocation).toBe(expectedLocation);
|
||||||
expect(container.querySelector('[data-testid="not-found-view"]')).toBeTruthy();
|
expect(container.querySelector('[data-testid="board-header"]')).toBeTruthy();
|
||||||
|
expect(container.querySelector('[data-testid="not-found-view"]')).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('redirects flash board catalog routes to not-found', async () => {
|
it('redirects flash board catalog routes to not-found', async () => {
|
||||||
|
|||||||
+5
-3
@@ -72,10 +72,12 @@ preloadReplyModal();
|
|||||||
|
|
||||||
const getPostFormRouteKeyPath = (pathname: string) => pathname.replace(/\/settings$/, '').replace(/\/$/, '');
|
const getPostFormRouteKeyPath = (pathname: string) => pathname.replace(/\/settings$/, '').replace(/\/$/, '');
|
||||||
|
|
||||||
|
const getPageOneCanonicalPath = (boardIdentifier: string, pathname: string) => `/${boardIdentifier}${pathname.endsWith('/settings') ? '/settings' : ''}`;
|
||||||
|
|
||||||
const BoardLayout = () => {
|
const BoardLayout = () => {
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
const { accountCommentIndex, boardIdentifier, pageNumber } = params;
|
const { accountCommentIndex, boardIdentifier, pageNumber } = params;
|
||||||
const { pathname, search } = useLocation();
|
const { pathname, search, hash } = useLocation();
|
||||||
const isMobile = useIsMobile();
|
const isMobile = useIsMobile();
|
||||||
const isInAllView = isAllView(pathname);
|
const isInAllView = isAllView(pathname);
|
||||||
const isInSubscriptionsView = isSubscriptionsView(pathname, useParams());
|
const isInSubscriptionsView = isSubscriptionsView(pathname, useParams());
|
||||||
@@ -113,8 +115,8 @@ const BoardLayout = () => {
|
|||||||
// force rerender of post form when navigating between pages, except when opening settings modal in current view
|
// force rerender of post form when navigating between pages, except when opening settings modal in current view
|
||||||
const key = `${communityAddress}-${getPostFormRouteKeyPath(pathname)}`;
|
const key = `${communityAddress}-${getPostFormRouteKeyPath(pathname)}`;
|
||||||
|
|
||||||
if (pageNumber === '1') {
|
if (pageNumber === '1' && boardIdentifier) {
|
||||||
return <Navigate to='/not-found' replace />;
|
return <Navigate to={{ pathname: getPageOneCanonicalPath(boardIdentifier, pathname), search, hash }} replace />;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isCatalogView(pathname, params) && isFlashBoardRoute(boardIdentifier, directories)) {
|
if (isCatalogView(pathname, params) && isFlashBoardRoute(boardIdentifier, directories)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user