Skip to content

Commit b028bc7

Browse files
authored
Merge pull request #9 from LooseWireDev/fix/empty-pagination-redirect
redirect empty pagination pages to stop bot crawl loops
2 parents e2aa496 + af45c9c commit b028bc7

4 files changed

Lines changed: 36 additions & 4 deletions

File tree

src/routes/apps/index.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createFileRoute, useNavigate } from "@tanstack/react-router";
1+
import { createFileRoute, redirect, useNavigate } from "@tanstack/react-router";
22
import { useState } from "react";
33
import { AppCard } from "~/components/app-card";
44
import { Breadcrumb } from "~/components/breadcrumb";
@@ -75,6 +75,14 @@ export const Route = createFileRoute("/apps/")({
7575
fetchTags(),
7676
]);
7777

78+
if (apps.length === 0 && page > 1) {
79+
throw redirect({
80+
to: "/apps",
81+
search: tagSlugs?.length ? { tags: tagSlugs.join(",") } : undefined,
82+
statusCode: 302,
83+
});
84+
}
85+
7886
const hasMore = apps.length > limit;
7987
const displayApps = hasMore ? apps.slice(0, limit) : apps;
8088

src/routes/category/$slug.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { createFileRoute, Link, notFound } from "@tanstack/react-router";
1+
import {
2+
createFileRoute,
3+
Link,
4+
notFound,
5+
redirect,
6+
} from "@tanstack/react-router";
27
import { AppCard } from "~/components/app-card";
38
import { Breadcrumb } from "~/components/breadcrumb";
49
import { JsonLd } from "~/components/json-ld";
@@ -33,6 +38,14 @@ export const Route = createFileRoute("/category/$slug")({
3338
data: { tagSlug: params.slug, page, limit: LIMIT + 1 },
3439
});
3540

41+
if (apps.length === 0 && page > 1) {
42+
throw redirect({
43+
to: "/category/$slug",
44+
params,
45+
statusCode: 302,
46+
});
47+
}
48+
3649
const hasMore = apps.length > LIMIT;
3750
const displayApps = hasMore ? apps.slice(0, LIMIT) : apps;
3851

src/routes/license/$license.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createFileRoute, notFound } from "@tanstack/react-router";
1+
import { createFileRoute, notFound, redirect } from "@tanstack/react-router";
22
import { AppCard } from "~/components/app-card";
33
import { Breadcrumb } from "~/components/breadcrumb";
44
import { JsonLd } from "~/components/json-ld";
@@ -30,6 +30,13 @@ export const Route = createFileRoute("/license/$license")({
3030
});
3131

3232
if (apps.length === 0 && page === 1) throw notFound();
33+
if (apps.length === 0 && page > 1) {
34+
throw redirect({
35+
to: "/license/$license",
36+
params,
37+
statusCode: 302,
38+
});
39+
}
3340

3441
const hasMore = apps.length > LIMIT;
3542
const displayApps = hasMore ? apps.slice(0, LIMIT) : apps;

src/routes/tags/$type/$slug.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createFileRoute, notFound } from "@tanstack/react-router";
1+
import { createFileRoute, notFound, redirect } from "@tanstack/react-router";
22
import { AppCard } from "~/components/app-card";
33
import { Breadcrumb } from "~/components/breadcrumb";
44
import { JsonLd } from "~/components/json-ld";
@@ -43,6 +43,10 @@ export const Route = createFileRoute("/tags/$type/$slug")({
4343
data: { tagSlug: params.slug, page, limit: LIMIT + 1 },
4444
});
4545

46+
if (apps.length === 0 && page > 1) {
47+
throw redirect({ to: "/tags/$type/$slug", params, statusCode: 302 });
48+
}
49+
4650
const hasMore = apps.length > LIMIT;
4751
const displayApps = hasMore ? apps.slice(0, LIMIT) : apps;
4852

0 commit comments

Comments
 (0)