I have a Megamenu extension installed replacing the default navigation menu. This however when added breaks breadcrumbs on product pages.
I have debugged by also removing both navigation and this also breaks the navigation so I believe the issue lies with default navigation being required somehow for breadcrumbs to work now. I could of sworn however this was working on 2.2.4 earlier this week as had below issue:
Issue with Magento 2.2.4 – quotation mark in product name break product pages
This i resolved however am sure did not break breadcrumbs as the time. Reverting does not fix breadcrumbs either.
How do breadcrumbs work now? They seem to load asynchronously and not sure they did before.
From what i can tell the below function in breadcrumbs.js renders the breadcrumbs:
_render: function () {
var html,
crumbs = breadcrumbList,
template = mageTemplate(tpl);
this._decorate(crumbs);
html = template({
'breadcrumbs': crumbs
});
if (html.length) {
$(this.element).html(html);
}
},
However im not sure how it grabs the data for the html
variable and why it breaks when i remove the default navigation.
Best Answer
With help of some posts on stackexchange, I found out this solution, This approach does not require you to override with di.xml
YOUR_THEME\Magento_Catalog\layout\catalog_product_view.xml
Create a module with the following block:
Vendor/Module/Block/Breadcrumbs.php
YOUR_THEME\Magento_Catalog\templates\product\breadcrumbs.phtml