Navigation Menu
A navigation menu allows your customers to navigate your store and find the products they are looking for.
Typically, navigation is based on a hierarchy of collections. We can get the top-level
collections using the collections query with the topLevelOnly filter:
Building a navigation tree
The collections query returns a flat list of collections, but we often want to display them in a tree-like structure.
This way, we can build up a navigation menu which reflects the hierarchy of collections.
First of all we need to ensure that we have the parentId property on each collection.
Then we can use this data to build up a tree structure. The following code snippet shows how this can be done in TypeScript:
Live example
Here's a live demo of the above code in action:
Was this chapter helpful?