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 };
};
apps/storefront/app/routes/products._index.tsx
which is not work:
this will work: