From f60c4257f47f7b7d1ae74550985327818729e37e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Str=C3=B8m-Andersen?= Date: Sun, 15 Nov 2026 15:06:29 +0100 Subject: [PATCH 1/2] fix: redirect from invalid pages to page 1 on books overview page --- frontend/app/routes/books.tsx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/frontend/app/routes/books.tsx b/frontend/app/routes/books.tsx index 7021cdd..4bd5cb4 100644 --- a/frontend/app/routes/books.tsx +++ b/frontend/app/routes/books.tsx @@ -6,7 +6,7 @@ import { SortSelect } from "~/components/books/SortSelect/SortSelect"; import { PageBreadcrumb } from "~/components/PageBreadcrumb/PageBreadcrumb"; import { useBookSearchParams } from "~/hooks/useBookSearchParams"; import { useSuggestedBooks } from "~/hooks/useSuggestedBooks"; -import { useSearchParams } from "react-router"; +import { Navigate, useSearchParams } from "react-router"; import { BOOK_PAGE_LIMIT } from "~/lib/constants"; export function meta() { @@ -73,6 +73,13 @@ export default function BooksPage() { const suggestionParams = new URLSearchParams(searchParams); suggestionParams.set("origin", "suggestions"); + // Redirect to page 1, keeping the search query, filters and sort + function redirectToFirstPage() { + const firstPageParams = new URLSearchParams(searchParams); + firstPageParams.delete("page"); + return ; + } + if (loading) { return (
@@ -103,7 +110,17 @@ export default function BooksPage() { ); } + // The page is beyond the last page of the search results + if (page > 1 && totalCount > 0 && books?.length === 0) { + return redirectToFirstPage(); + } + if (!books || books.length === 0) { + // The page is beyond the last page of the suggestions + if (page > 1 && suggestions?.length === 0 && suggestionCount > 0) { + return redirectToFirstPage(); + } + if (suggestions && suggestions.length > 0) { return (
From 85978580f95207dd3676718ecdf87aed612b1679 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Str=C3=B8m-Andersen?= Date: Mon, 16 Nov 2026 11:50:36 +0100 Subject: [PATCH 2/2] fix: avoid "no books found" flash before redirecting from invalid page Co-authored-by: Martin Alexander Kaminski Co-authored-by: Martin Alexander Kaminski --- frontend/app/routes/books.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/app/routes/books.tsx b/frontend/app/routes/books.tsx index c0d59fb..3cfcc47 100644 --- a/frontend/app/routes/books.tsx +++ b/frontend/app/routes/books.tsx @@ -137,7 +137,7 @@ export default function BooksPage() { // Later loads keep showing the previous books until the new ones arrive, // unless it takes a while - if ((loading && !books) || slowLoading) { + if ((loading && !books?.length) || slowLoading) { return (