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:
Tommaso Casaburi
2026-06-27 17:02:51 +07:00
parent 292d3e35a4
commit eacb422f40
2 changed files with 14 additions and 7 deletions
+9 -4
View File
@@ -431,11 +431,16 @@ describe('App', () => {
expect(container.querySelector('[data-testid="board-blotter"]')).toBeTruthy();
});
it('redirects board page 1 feeds to not-found', async () => {
await renderApp('/mu/1');
it.each([
['/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(container.querySelector('[data-testid="not-found-view"]')).toBeTruthy();
expect(latestLocation).toBe(expectedLocation);
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 () => {
+5 -3
View File
@@ -72,10 +72,12 @@ preloadReplyModal();
const getPostFormRouteKeyPath = (pathname: string) => pathname.replace(/\/settings$/, '').replace(/\/$/, '');
const getPageOneCanonicalPath = (boardIdentifier: string, pathname: string) => `/${boardIdentifier}${pathname.endsWith('/settings') ? '/settings' : ''}`;
const BoardLayout = () => {
const params = useParams();
const { accountCommentIndex, boardIdentifier, pageNumber } = params;
const { pathname, search } = useLocation();
const { pathname, search, hash } = useLocation();
const isMobile = useIsMobile();
const isInAllView = isAllView(pathname);
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
const key = `${communityAddress}-${getPostFormRouteKeyPath(pathname)}`;
if (pageNumber === '1') {
return <Navigate to='/not-found' replace />;
if (pageNumber === '1' && boardIdentifier) {
return <Navigate to={{ pathname: getPageOneCanonicalPath(boardIdentifier, pathname), search, hash }} replace />;
}
if (isCatalogView(pathname, params) && isFlashBoardRoute(boardIdentifier, directories)) {