diff --git a/src/routes/apps/index.tsx b/src/routes/apps/index.tsx index d88c66f..c6e0179 100644 --- a/src/routes/apps/index.tsx +++ b/src/routes/apps/index.tsx @@ -1,4 +1,4 @@ -import { createFileRoute, useNavigate } from "@tanstack/react-router"; +import { createFileRoute, redirect, useNavigate } from "@tanstack/react-router"; import { useState } from "react"; import { AppCard } from "~/components/app-card"; import { Breadcrumb } from "~/components/breadcrumb"; @@ -75,6 +75,14 @@ export const Route = createFileRoute("/apps/")({ fetchTags(), ]); + if (apps.length === 0 && page > 1) { + throw redirect({ + to: "/apps", + search: tagSlugs?.length ? { tags: tagSlugs.join(",") } : undefined, + statusCode: 302, + }); + } + const hasMore = apps.length > limit; const displayApps = hasMore ? apps.slice(0, limit) : apps; diff --git a/src/routes/category/$slug.tsx b/src/routes/category/$slug.tsx index 3bc6781..e3ce11f 100644 --- a/src/routes/category/$slug.tsx +++ b/src/routes/category/$slug.tsx @@ -1,4 +1,9 @@ -import { createFileRoute, Link, notFound } from "@tanstack/react-router"; +import { + createFileRoute, + Link, + notFound, + redirect, +} from "@tanstack/react-router"; import { AppCard } from "~/components/app-card"; import { Breadcrumb } from "~/components/breadcrumb"; import { JsonLd } from "~/components/json-ld"; @@ -33,6 +38,14 @@ export const Route = createFileRoute("/category/$slug")({ data: { tagSlug: params.slug, page, limit: LIMIT + 1 }, }); + if (apps.length === 0 && page > 1) { + throw redirect({ + to: "/category/$slug", + params, + statusCode: 302, + }); + } + const hasMore = apps.length > LIMIT; const displayApps = hasMore ? apps.slice(0, LIMIT) : apps; diff --git a/src/routes/license/$license.tsx b/src/routes/license/$license.tsx index 4d3cbb5..d1e3c30 100644 --- a/src/routes/license/$license.tsx +++ b/src/routes/license/$license.tsx @@ -1,4 +1,4 @@ -import { createFileRoute, notFound } from "@tanstack/react-router"; +import { createFileRoute, notFound, redirect } from "@tanstack/react-router"; import { AppCard } from "~/components/app-card"; import { Breadcrumb } from "~/components/breadcrumb"; import { JsonLd } from "~/components/json-ld"; @@ -30,6 +30,13 @@ export const Route = createFileRoute("/license/$license")({ }); if (apps.length === 0 && page === 1) throw notFound(); + if (apps.length === 0 && page > 1) { + throw redirect({ + to: "/license/$license", + params, + statusCode: 302, + }); + } const hasMore = apps.length > LIMIT; const displayApps = hasMore ? apps.slice(0, LIMIT) : apps; diff --git a/src/routes/tags/$type/$slug.tsx b/src/routes/tags/$type/$slug.tsx index e66fb7f..1403569 100644 --- a/src/routes/tags/$type/$slug.tsx +++ b/src/routes/tags/$type/$slug.tsx @@ -1,4 +1,4 @@ -import { createFileRoute, notFound } from "@tanstack/react-router"; +import { createFileRoute, notFound, redirect } from "@tanstack/react-router"; import { AppCard } from "~/components/app-card"; import { Breadcrumb } from "~/components/breadcrumb"; import { JsonLd } from "~/components/json-ld"; @@ -43,6 +43,10 @@ export const Route = createFileRoute("/tags/$type/$slug")({ data: { tagSlug: params.slug, page, limit: LIMIT + 1 }, }); + if (apps.length === 0 && page > 1) { + throw redirect({ to: "/tags/$type/$slug", params, statusCode: 302 }); + } + const hasMore = apps.length > LIMIT; const displayApps = hasMore ? apps.slice(0, LIMIT) : apps;