Files
dusuniot/src/routes/blog.page.$page.tsx
T

33 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* # 路由 博客归档分页 /blog/page/$page/
* 与原站一致的第 2+ 页归档(每页 12 篇,日期倒序)。
*/
import { createFileRoute, notFound } from "@tanstack/react-router";
import { BlogArchive, loadBlogArchive } from "~/components/website/BlogArchive";
export const Route = createFileRoute("/blog/page/$page")({
loader: async ({ params }) => {
const n = Number(params.page);
const data = await loadBlogArchive(Number.isFinite(n) && n > 1 ? Math.floor(n) : 1);
// 越界页真 404(原站 /blog/page/28/ 404;软 404 影响 SEO)
if (!Number.isFinite(n) || n < 1 || (data.page > 1 && data.page > Math.ceil(data.list.total / data.list.pageSize)))
throw notFound();
return data;
},
head: ({ loaderData }) => ({
meta: [
{
title: `Blog - Page ${loaderData?.page ?? 2} of ${loaderData ? Math.max(1, Math.ceil(loaderData.list.total / loaderData.list.pageSize)) : 2} - DusunIoT`,
},
{ name: "description", content: "IoT guides, industry insights, product news and tutorials from Dusun IoT experts." },
],
}),
component: BlogArchivePagedPage,
});
/** # 组件 博客归档分页页 */
function BlogArchivePagedPage() {
const data = Route.useLoaderData();
return <BlogArchive data={data} />;
}