gpt4 book ai didi

Get params for category and page(获取类别和页面的参数)

转载 作者:bug小助手 更新时间:2023-10-26 20:10:02 26 4
gpt4 key购买 nike



I use this on my blog homepage to have pagination. The pages are like url/?page=2 etc.

我在我的博客主页上使用这个来进行分页。这些页面类似于url/?Page=2等。


export default async function HomePage({
searchParams,
}: {
searchParams: {[key: string]: string | string[] | undefined};
}) {
const DataPosts = await getPostsNumber();
const PostsNumber = DataPosts.postCount;

const page = getNumericParam(searchParams.pagina, 1);
const limit = getNumericParam(searchParams.numar, 10);

Works like a charm. Now i'm trying to do the same for categories pages. Here I already have params to get the category name. How can i add the ones for pagination ?

就像一种护身符。现在我正试着为分类页面做同样的事情。在这里,我已经有了参数来获取类别名称。我如何才能添加要分页的那些?


export async function generateMetadata({params}: {params: {category: string}}) {
const slug = params.category;

I tried this:

我试过这个:


export default async function Page({
params,
}: {
params: {category: string; [key: string]: string | string[] | undefined};
}) {
const slug = params.category;

const DataPosts = await getPostsNumber(slug);
const PostsNumber = DataPosts.categories[0].count;

const page = getNumericParam(params.pagina, 1);
const limit = getNumericParam(params.numar, 10);


But params always returns "{ category: 'name' }" and no page.

但是PARAMS总是返回“{ategory:‘name’}”,没有页面。


更多回答
优秀答案推荐

Since you are using Next.js app router, you can retrieve the url query param using:

由于您使用的是Next.js应用程序路由器,因此可以使用以下命令检索url查询参数:


export default async function Page({
params,
searchParams,
}: {
params: { category: string };
searchParams?: { [key: string]: string | string[] | undefined }
}) {
const slug = params.category;

const DataPosts = await getPostsNumber(slug);
const PostsNumber = DataPosts.categories[0].count;

const page = getNumericParam(searchParams?.pagina, 1);
const limit = getNumericParam(searchParams?.numar, 10);


更多回答

Thanks! The thing is would like to keep the page a server component. Any way with this?

谢谢!事情是想保持页面的服务器组件。有什么办法吗?

Have updated my answer. Can you check if works for you?

已经更新了我的答案。你能检查一下对你是否有效吗?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com