The CategoryPage component
Like for the search page, we’re layering an SPA on top of your site to enable fast client side routing between the category pages.
Set up and configure your product listing pages using the CategoryPage
component and a PageReplacer as follows.
import { CategoryPage, SetupPageReplacer } from "@depict-ai/js-ui";
SetupPageReplacer({
isPageToReplace: url => url.pathname == "/category.html",
selectorToReplace: `.replace-for-depict`,
renderContent: () =>
CategoryPage({
categoryProvider,
productCard,
}),
});
Review the types or
reference for other configurable properties
Different layout possibilities
The default configuration displays the current category title above the product cards.
If you want to render the title of the category yourself, do the following to remove the default title and also make the CategoryPage as compact as possible:
import { CategoryPage, SetupPageReplacer, EmbeddedNumProducts } from "@depict-ai/js-ui";
SetupPageReplacer({
isPageToReplace: url => url.pathname == "/category.html",
selectorToReplace: `.replace-for-depict`,
renderContent: () =>
CategoryPage({
categoryTitlePlugin: EmbeddedNumProducts,
categoryProvider,
productCard,
}),
});
The CategoryPage in its most compact version, optimizing for the content being above the fold
Navigating to category pages without reloading the page
You can link to the category pages and then PageReplacer will only single-page-navigate between the different category pages.
If you, however, want to replace the current page with a category page without a reload, you can do the following:
<a href="URL_OF_CATEGORY" data-category-id="CATEGORY-ID" class="category-link">CATEGORY_NAME</a>
import { onExistsObserver } from "@depict-ai/js-ui";
onExistsObserver("a.category-link", element => element.addEventListener("click", ev => {
if (ev.button || ev.metaKey || ev.ctrlKey) return;
const new_id = element.dataset.listingId!;
history.pushState({ ...history.state }, "", element.href;
categoryProvider.listingQuery = { type: "listingId", id: new_id };
}));