Magento – Magento 2 – How to remove main navigation from XML

magento-2.1magento2navigationxml

We want to remove Magento's default main navigation using xml file but don't want to use remove, because ifconfig not working with remove.

We want to remove main navigation only when our custom module is disabled.

We have tried below codes but it's not working.

// CODE 1
<referenceContainer name="store.menu">
    <action method="unsetChild" ifconfig="rootmegamenu_option/general/enable">
        <argument name="alias" xsi:type="string">catalog.topnav</argument>
    </action>
</referenceContainer>

// CODE 2
<referenceContainer name="store.menu">
     <action method="unsetChild"><child>catalog.topnav</child></action>
</referenceContainer>

// CODE 3
<referenceContainer name="store.menu">
     <action method="unsetChild" ><name>catalog.topnav</name></action>
</referenceContainer>

Help will be appreciated.

Best Answer

This is a very late response, but I just managed to do this by adding the following to my default.xml file:

<referenceBlock name="navigation.sections" display="false" />

I found out the element name by looking around in /vendor/magento/module-theme/view/frontend/layout/default.xml.