Signature
Import
About this widget
Thebreadcrumb
widget is a secondary navigation scheme that lets users see where the current page is in relation to the facet’s hierarchy.
It reduces the number of actions a user needs to take to get to a higher-level page and improves the discoverability of the app or website’s sections and pages.
It is commonly used for websites with lot of data, organized into categories with subcategories.
Requirements
The objects to use in the breadcrumb must follow this structure:JSON
JSON
- Decide on an appropriate facet hierarchy
- Determine your
attributes
for faceting from the dashboard or with an API client - Display the UI with the hierarchical menu widget.
>
(with spaces),
but you can use a different one by using the separator option.
If there is also a hierarchicalMenu
on the page,
it must follow the same configuration.
Examples
JavaScript
Options
The CSS Selector or
HTMLElement
to insert the widget into.An array of attributes to generate the breadcrumb.
JavaScript
The path to use if the first level is not the root level.Make sure to also include the root path in your UI state,
for example, by setting
initialUiState
or calling setUiState()
.JavaScript
The level separator used in the records.
JavaScript
The CSS classes you can override:
root
. The root element of the widget.noRefinementRoot
. The root element if there are no refinements.list
. The list of results.item
. The list items. They contain the link and separator.selectedItem
. The selected item in the list. This is the last one, or the root one if there are no refinements.separator
. The separator.link
. The links in each item.
JavaScript
A function that receives the list of items before they are displayed.
It should return a new array with the same structure.
Use this to transform, filter, or reorder the items.The function also has access to the full
results
data,
including all standard response parameters
and parameters from the helper,
such as disjunctiveFacetsRefinements
.JavaScript
Templates
You can customize parts of a widget’s UI using the Templates API. Each template includes anhtml
function,
which you can use as a tagged template.
This function safely renders templates as HTML strings and works directly in the browser—no build step required.
For details, see Templating your UI.
The
html
function is available in InstantSearch.js version 4.46.0 or later.The label of the breadcrumb’s first element.
The symbol used to separate the elements of the breadcrumb.
HTML output
HTML
Customize the UI with connectBreadcrumb
If you want to create your own UI of the breadcrumb
widget, you can use connectors.
To use connectBreadcrumb
, you can import it with the declaration relevant to how you installed InstantSearch.js.
JavaScript
Create a render function
This rendering function is called before the first search (init
lifecycle step)
and each time results come back from Algolia (render
lifecycle step).
JavaScript
If SEO is important for your search page, ensure that your custom HTML is optimized for search engines:
- Use
<a>
tags withhref
attributes to allow search engine bots to follow links. - Use semantic HTML and include structured data when relevant.
Render options
The items to render, containing the keys:
label
. The label of the category or subcategory.value
. The value of breadcrumb item.
JavaScript
Indicates if search state can be refined.
JavaScript
All original widget options forwarded to the render function.
JavaScript
Create and instantiate the custom widget
First, create your custom widgets using a rendering function. Then, instantiate them with parameters. There are two kinds of parameters you can pass:- Instance parameters. Predefined options that configure Algolia’s behavior.
- Custom parameters. Parameters you define to make the widget reusable and adaptable.
renderFunction
, both instance and custom parameters are accessible through connector.widgetParams
.
JavaScript
Instance options
The attributes to use to generate the hierarchy of the breadcrumb.
JavaScript
The path to use if the first level is not the root level.Make sure to also include the root path in your UI state,
for example, by setting
initialUiState
or calling setUiState()
.JavaScript
The level separator used in the records.
JavaScript
A function that receives the list of items before they are displayed.
It should return a new array with the same structure.
Use this to transform, filter, or reorder the items.The function also has access to the full
results
data,
including all standard response parameters
and parameters from the helper,
such as disjunctiveFacetsRefinements
.JavaScript