Magento – Magento 2 How to over write route FrontName of a module

di.xmlmagento2modulerouter

I'm trying to extend Magento 2 default module Magente_Contact, but I can't change the frontName, I tried to put in the di.xml, but nothing happens.

<config>
    <router id="standart">
        <route id="contact" frontName="contato">
            <module name="[VENDOR]_Contact" />
        </route>
    </router>
</config>


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
  <preference for="Magento\Contact\etc\frontend\routes" type="{Vendor}\{Module}\etc\front\routes" />
</config>

Best Answer

There is a tricky way,you can change the contact us Magento_Contact module's frontend Name

First, etc/module.xml of your module's make Magento_Contact as a depended module.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="[Vendor]_[ModuleName]" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Contact"/>
        </sequence>
    </module>
</config>

And then changes frontend name from routes.xml at etc/frontend/.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="standard">
        <route id="contact" frontName="contato">
            <module name="Magento_Contact" />
        </route>
    </router>
</config>

di.xml is not required