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();
|
||||
});
|
||||
|
||||
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
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user