Breadcrumbs for PLP and PDP#1256
Conversation
|
Hello, I'm the AEM Code Sync Bot and I will run some actions to deploy your branch and validate page speed.
|
…recording - Introduced a new "Commerce Breadcrumbs" component in component-definition.json and component-models.json. - Implemented breadcrumb trail recording in header.js and product-list-page.js to enhance navigation tracking.
…pecific product list page - Changed the event listener to only trigger on clicks within the 'main .product-list-page' element. - Updated README to reflect the change in the link click context for breadcrumb trail recording.
| @@ -0,0 +1,41 @@ | |||
| # Commerce Breadcrumbs | |||
|
|
|||
| Renders a breadcrumb using the SDK `Breadcrumbs` component (`@dropins/tools/components.js`). | |||
There was a problem hiding this comment.
Is this block able to work on any page? Would it be added to a PDP document and a PLP document? Can it be added to other pages?
There was a problem hiding this comment.
Drop it in wherever you want a breadcrumb. The PLP→PDP trail propagation is the only "smart" commerce feature, and it gracefully degrades to "just render what the author wrote" everywhere else.
There was a problem hiding this comment.
Can you note this (verbatim?) in this README somewhere?
| const anchor = event.target.closest('a'); | ||
| if (!anchor) return; | ||
| const targetPath = new URL(anchor.href).pathname; |
There was a problem hiding this comment.
I still think there's a chance this could be wrong. For example, the product-list-page block could be modified to show anchor links elsewhere within the tree under .product-list-page and then clicking those would add to the trail.
There was a problem hiding this comment.
The first solution I provided was filtering anchors pointing to /products/, but some customer don't have /products/ in their URLs. After reviewing the PLP, I noticed that all interactions use buttons, so I thought it would be simpler to handle it that way.
Do you have an example of a link within the PLP that navigates to a different page?
Anyway, in the worst case scenario, it will store the link path and breadcrumb trail in session storage, but no one will use it, so nothing should really break.
There was a problem hiding this comment.
Do you have an example of a link within the PLP that navigates to a different page?
No, I don't have off top of my head. This might just be edge case. I just wanted to raise it so we spent some braincells on it :D
There was a problem hiding this comment.
If required, we could add a class name to the anchors in the PLP dropin so that we can filter them.
…feature, with fallback behavior for other contexts.
|
Adding a documentation tutorial based on this implementation here: commerce-docs/microsite-commerce-storefront#928 Closing this for now, but we may reopen it in the future if we decide to provide this solution out of the box. |
demo.mov
Commerce Breadcrumbs Spike
This PR introduces a new
commerce-breadcrumbsblock (README) to render breadcrumb navigation on PLP and PDP.Authoring
The block reads its content directly from the HTML. Author an
<ol>(or<ul>) with one<li>per crumb, in order. Wrap a crumb in<a>to make it a link; leave the last one as plain text for the current page.Renders as:
Home / Men / Men's Clothing / Sprite Yoga StrapEvery crumb (including
Home) is provided by the author; the block does not prepend or append anything. The last<li>is always treated as the leaf (current page) and rendered as plain text — its position determines that, not the absence of a link.Runtime behavior
The block parses the authored
<ol>into a flat list of crumbs and renders them through the SDK Breadcrumbs component — ancestors as links, leaf as plain text.PLP → PDP navigation context
The block also acts as a producer of navigation context. It listens for clicks on any link inside
main .product-list-pageand persists the full breadcrumb of the current page ([...ancestors, current]) intosessionStorage, keyed to the destination product path.For example, on PLP
/men/clothingthe rendered breadcrumb is:When the user clicks a product card, the block writes:
{ "path": "/products/<product>", "trail": [ { "label": "Home", "url": "/" }, { "label": "Men", "url": "/men" }, { "label": "Men's Clothing", "url": "/men/clothing" } ] }On the PDP, if the stored entry's
pathmatches the current pathname, itstrailreplaces the authored ancestors, while the leaf still comes from the PDP's own authored HTML:i.e. PDP breadcrumbs reflect the actual path the user took, not just the PDP's own authored trail.
Prerender requirement
For both PLP and PDP, it is recommended that
aem-commerce-prerenderemits the full breadcrumb<ol>in the block's HTML, including:Homeas the first<li><li>items<li>(plain text, no link)This guarantees deterministic breadcrumbs on direct loads and also enables the contextual override when navigating from PLP (or any page with the breadcrumb block) to PDP. Authors can alternatively define the same
<ol>directly in DA on a per-page basis.Test URLs: