Skip to content

Product page pagination issue #62

Description

@chris-fung

apps/storefront/app/routes/products._index.tsx

which is not work:

export const loader = async ({ request }: LoaderFunctionArgs) => {
  const { products, count, limit, offset } = await fetchProducts(request, {});

  return { products, count, limit, offset };
};

this will work:

export const loader = async ({ request }: LoaderFunctionArgs) => {
  const url = new URL(request.url);
  const pageNumber = url.searchParams.get('page'); // 获取 'page' 参数的值

  const query = {} as any;
  if (pageNumber && !isNaN(Number(pageNumber))) {
    query.limit = 50;
    query.offset = (Number(pageNumber) - 1) * query.limit;
  }

  const { products, count, limit, offset } = await fetchProducts(request, query);

  return { products, count, limit, offset };
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions