Displays a navigation breadcrumb for hierarchical facets, allowing users to see and modify their current refinement path.
Usage
import instantsearch from 'instantsearch.js';
import { breadcrumb } from 'instantsearch.js/es/widgets';
const search = instantsearch({
indexName: 'instant_search',
searchClient
});
search.addWidgets([
breadcrumb({
container: '#breadcrumb',
attributes: [
'hierarchicalCategories.lvl0',
'hierarchicalCategories.lvl1',
'hierarchicalCategories.lvl2'
]
})
]);
search.start();
Parameters
container
string | HTMLElement
required
CSS selector or HTMLElement to insert the widget.
Array of attribute names to use for generating the breadcrumb hierarchy.
The level separator used in the records.
Prefix path to use if the first level is not the root level.
Function to transform the items passed to the templates.(items: BreadcrumbItem[]) => BreadcrumbItem[]
Templates to use for the widget.
Label of the breadcrumb’s first element.Default: 'Home'
Symbol used to separate the elements of the breadcrumb.Default: '>'
CSS classes to add to the widget elements.
CSS class to add to the root element.
CSS class to add to the root element when there are no refinements.
CSS class to add to the list element.
CSS class to add to the items of the list.
CSS class to add to the selected item in the list.
CSS class to add to the separator.
CSS class to add to the links in the items.
Examples
Custom separator
breadcrumb({
container: '#breadcrumb',
attributes: [
'hierarchicalCategories.lvl0',
'hierarchicalCategories.lvl1',
'hierarchicalCategories.lvl2'
],
templates: {
separator: ' / '
}
});
With root path
breadcrumb({
container: '#breadcrumb',
attributes: [
'hierarchicalCategories.lvl0',
'hierarchicalCategories.lvl1',
'hierarchicalCategories.lvl2'
],
rootPath: 'Products',
templates: {
home: 'All Products'
}
});
HTML output
<div class="ais-Breadcrumb">
<ul class="ais-Breadcrumb-list">
<li class="ais-Breadcrumb-item">
<a class="ais-Breadcrumb-link" href="#">Home</a>
<span class="ais-Breadcrumb-separator">></span>
</li>
<li class="ais-Breadcrumb-item">
<a class="ais-Breadcrumb-link" href="#">Appliances</a>
<span class="ais-Breadcrumb-separator">></span>
</li>
<li class="ais-Breadcrumb-item ais-Breadcrumb-item--selected">
Dishwashers
</li>
</ul>
</div>